Skip to content

Commit

Permalink
Move defer out of function body. (#259)
Browse files Browse the repository at this point in the history
After `sse.NewHandler` was moved to fucntion, `defer` was
called everytime handler was created not just before exiting `main`.
  • Loading branch information
janisz authored Aug 4, 2017
1 parent e108886 commit 7566270
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ func main() {

sync.New(config.Sync, remote, consulInstance, consulInstance.AddAgentsFromApps).StartSyncServicesJob()

//TODO: Use context instead of stop function.
var stopSSE sse.Stop
go func() {
stopSSE, err := sse.NewHandler(config.SSE, config.Web, remote, consulInstance)
stopSSE, err = sse.NewHandler(config.SSE, config.Web, remote, consulInstance)
if err != nil {
log.WithError(err).Fatal("Cannot instantiate SSE handler")
}
defer stopSSE()
}()
defer stopSSE()

http.HandleFunc("/health", web.HealthHandler)

Expand Down

0 comments on commit 7566270

Please sign in to comment.