This commit is contained in:
		| @@ -22,8 +22,11 @@ func ActionServe(c *cli.Context) error { | ||||
| 		configPath = c.String("config") | ||||
| 	} | ||||
|  | ||||
| 	var cfg *gpaste.ServerConfig | ||||
| 	var r io.ReadCloser | ||||
| 	var ( | ||||
| 		cfg *gpaste.ServerConfig | ||||
| 		r   io.ReadCloser | ||||
| 	) | ||||
|  | ||||
| 	r, err := os.Open(configPath) | ||||
| 	if err != nil { | ||||
| 		cfg = &gpaste.ServerConfig{ | ||||
| @@ -52,8 +55,10 @@ func ActionServe(c *cli.Context) error { | ||||
| 	// Setup contexts for clean shutdown | ||||
| 	rootCtx, rootCancel := signal.NotifyContext(context.Background(), os.Interrupt) | ||||
| 	defer rootCancel() | ||||
|  | ||||
| 	httpCtx, httpCancel := context.WithCancel(rootCtx) | ||||
| 	defer httpCancel() | ||||
|  | ||||
| 	httpShutdownCtx, httpShutdownCancel := context.WithCancel(context.Background()) | ||||
| 	defer httpShutdownCancel() | ||||
|  | ||||
| @@ -66,14 +71,18 @@ func ActionServe(c *cli.Context) error { | ||||
| 		// Wait for cancel | ||||
| 		go func() { | ||||
| 			<-httpCtx.Done() | ||||
| 			timeoutCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||||
|  | ||||
| 			timeoutCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second) // nolint: gomnd | ||||
| 			defer cancel() | ||||
| 			srv.Shutdown(timeoutCtx) | ||||
|  | ||||
| 			_ = srv.Shutdown(timeoutCtx) | ||||
| 		}() | ||||
| 		serverLogger.Infow("Starting HTTP server.", "addr", cfg.ListenAddr) | ||||
|  | ||||
| 		if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||||
| 			serverLogger.Errorw("Error during shutdown.", "error", err) | ||||
| 		} | ||||
|  | ||||
| 		serverLogger.Infow("HTTP server shutdown complete.", "addr", cfg.ListenAddr) | ||||
| 		httpShutdownCancel() | ||||
| 	}() | ||||
|   | ||||
| @@ -29,5 +29,5 @@ func main() { | ||||
| 		Action: actions.ActionServe, | ||||
| 	} | ||||
|  | ||||
| 	app.Run(os.Args) | ||||
| 	_ = app.Run(os.Args) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user