Skip to content

Commit

Permalink
Slightly improve error handling
Browse files Browse the repository at this point in the history
Pass errors from Cobra runRoot() to main().
  • Loading branch information
zcalusic committed Jul 30, 2017
1 parent a628c4e commit 57ca1d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions cmd/rest-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func runRoot(cmd *cobra.Command, args []string) error {
if restserver.Config.CPUProfile != "" {
f, err := os.Create(restserver.Config.CPUProfile)
if err != nil {
log.Fatal(err)
return err
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal(err)
return err
}
log.Println("CPU profiling enabled")
defer pprof.StopCPUProfile()
Expand Down Expand Up @@ -75,12 +75,8 @@ func runRoot(cmd *cobra.Command, args []string) error {
log.Printf("Starting server on %s\n", restserver.Config.Listen)
err = http.ListenAndServeTLS(restserver.Config.Listen, publicKey, privateKey, handler)
}
if err != nil {
log.Fatal(err)
}

return nil

return err
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func debugHandler(next http.Handler) http.Handler {
func logHandler(next http.Handler) http.Handler {
accessLog, err := os.OpenFile(Config.Log, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Fatal(err)
log.Fatalf("error: %v", err)
}

return handlers.CombinedLoggingHandler(accessLog, next)
Expand Down

0 comments on commit 57ca1d7

Please sign in to comment.