mirror of
https://github.com/restic/rest-server.git
synced 2025-12-06 17:15:45 -08:00
Slightly improve error handling
Pass errors from Cobra runRoot() to main().
This commit is contained in:
@@ -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()
|
||||
@@ -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() {
|
||||
|
||||
2
mux.go
2
mux.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user