Improve startServer function

- reorder parameters to match other functions
- move context.Background call into function
main
Jan Dittberner 10 months ago
parent f3be6959ab
commit a0a86f1980

@ -65,7 +65,7 @@ func main() {
config, err := services.ConfigureApplication(logger, "IDP", services.DefaultConfig) config, err := services.ConfigureApplication(logger, "IDP", services.DefaultConfig)
if err != nil { if err != nil {
log.Fatalf("error loading configuration: %v", err) logger.WithError(err).Fatal("error loading configuration")
} }
if level := config.String("log.level"); level != "" { if level := config.String("log.level"); level != "" {
@ -142,7 +142,7 @@ func main() {
handlerChain := tracing(logging(hsts(errorMiddleware(csrfProtect(router))))) handlerChain := tracing(logging(hsts(errorMiddleware(csrfProtect(router)))))
startServer(context.Background(), handlerChain, logger, config) startServer(logger, config, handlerChain)
} }
func configureAdminClient(config *koanf.Koanf) (*client.Runtime, error) { func configureAdminClient(config *koanf.Koanf) (*client.Runtime, error) {
@ -178,7 +178,7 @@ func configureAdminClient(config *koanf.Koanf) (*client.Runtime, error) {
return clientTransport, nil return clientTransport, nil
} }
func startServer(ctx context.Context, handlerChain http.Handler, logger *log.Logger, config *koanf.Koanf) { func startServer(logger *log.Logger, config *koanf.Koanf, handlerChain http.Handler) {
clientCertificateCAFile := config.MustString("security.client.ca-file") clientCertificateCAFile := config.MustString("security.client.ca-file")
serverBindAddress := config.String("server.bind_address") serverBindAddress := config.String("server.bind_address")
serverName := config.String("server.name") serverName := config.String("server.name")
@ -217,7 +217,7 @@ func startServer(ctx context.Context, handlerChain http.Handler, logger *log.Log
logger.Infoln("Server is shutting down...") logger.Infoln("Server is shutting down...")
atomic.StoreInt32(&handlers.Healthy, 0) atomic.StoreInt32(&handlers.Healthy, 0)
ctx, cancel := context.WithTimeout(ctx, ShutdownTimeout) ctx, cancel := context.WithTimeout(context.Background(), ShutdownTimeout)
defer cancel() defer cancel()
server.SetKeepAlivesEnabled(false) server.SetKeepAlivesEnabled(false)

Loading…
Cancel
Save