diff options
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -16,18 +16,18 @@ import ( var mx *mxlib.Client -func StartAppService(errch chan error) error { +func StartAppService(errch chan error) (*http.Server, error) { mx = mxlib.NewClient(config.Server, registration.AsToken) err := InitDb() if err != nil { - return err + return nil, err } if dbKvGet("ezbr_initialized") != "yes" { err = mx.RegisterUser(registration.SenderLocalpart) if mxe, ok := err.(*mxlib.MxError); !ok || mxe.ErrCode != "M_USER_IN_USE" { - return err + return nil, err } _, st := os.Stat(config.AvatarFile) @@ -36,13 +36,13 @@ func StartAppService(errch chan error) error { Path: config.AvatarFile, }) if err != nil { - return err + return nil, err } } err = mx.ProfileDisplayname(ezbrMxId(), fmt.Sprintf("Easybridge (%s)", EASYBRIDGE_SYSTEM_PROTOCOL)) if err != nil { - return err + return nil, err } dbKvPut("ezbr_initialized", "yes") @@ -52,9 +52,13 @@ func StartAppService(errch chan error) error { router.HandleFunc("/_matrix/app/v1/transactions/{txnId}", handleTxn) router.HandleFunc("/transactions/{txnId}", handleTxn) + log.Printf("Starting HTTP server on %s", config.ASBindAddr) + http_server := &http.Server{ + Addr: config.ASBindAddr, + Handler: checkTokenAndLog(router), + } go func() { - log.Printf("Starting HTTP server on %s", config.ASBindAddr) - err := http.ListenAndServe(config.ASBindAddr, checkTokenAndLog(router)) + err := http_server.ListenAndServe() if err != nil { errch <- err } @@ -71,7 +75,7 @@ func StartAppService(errch chan error) error { } }() - return nil + return http_server, nil } func checkTokenAndLog(handler http.Handler) http.Handler { |