diff --git a/support/http/logging_middleware.go b/support/http/logging_middleware.go index 90f7e43f02..0a2f784051 100644 --- a/support/http/logging_middleware.go +++ b/support/http/logging_middleware.go @@ -30,12 +30,12 @@ func SetLoggerMiddleware(l *log.Entry) func(stdhttp.Handler) stdhttp.Handler { // LoggingMiddleware is a middleware that logs requests to the logger. func LoggingMiddleware(next stdhttp.Handler) stdhttp.Handler { - return LoggingMiddlewareWithOptions(nil)(next) + return LoggingMiddlewareWithOptions(Options{})(next) } // LoggingMiddlewareWithOptions is a middleware that logs requests to the logger. // Requires an Options struct to accept additional information. -func LoggingMiddlewareWithOptions(options *Options) func(stdhttp.Handler) stdhttp.Handler { +func LoggingMiddlewareWithOptions(options Options) func(stdhttp.Handler) stdhttp.Handler { return func(next stdhttp.Handler) stdhttp.Handler { return stdhttp.HandlerFunc(func(w stdhttp.ResponseWriter, r *stdhttp.Request) { mw := mutil.WrapWriter(w) @@ -46,11 +46,7 @@ func LoggingMiddlewareWithOptions(options *Options) func(stdhttp.Handler) stdhtt }) r = r.WithContext(ctx) - extraHeaders := []string{} - if options != nil { - extraHeaders = options.extraHeaders - } - logStartOfRequest(r, extraHeaders...) + logStartOfRequest(r, options.ExtraHeaders) then := time.Now() next.ServeHTTP(mw, r) @@ -65,7 +61,7 @@ func LoggingMiddlewareWithOptions(options *Options) func(stdhttp.Handler) stdhtt // beginning processing. func logStartOfRequest( r *stdhttp.Request, - extraHeaders ...string, + extraHeaders []string, ) { fields := log.F{} for _, header := range extraHeaders { diff --git a/support/http/logging_middleware_test.go b/support/http/logging_middleware_test.go index 8ed485c76b..00881617e3 100644 --- a/support/http/logging_middleware_test.go +++ b/support/http/logging_middleware_test.go @@ -103,8 +103,7 @@ func TestHTTPMiddlewareWithOptions(t *testing.T) { mux.Use(setXFFMiddleware) mux.Use(setContentMD5Middleware) mux.Use(middleware.RequestID) - extraHeaders := []string{"X-Forwarded-For", "Content-MD5"} - options := &Options{extraHeaders: extraHeaders} + options := Options{ExtraHeaders: []string{"X-Forwarded-For", "Content-MD5"}} mux.Use(LoggingMiddlewareWithOptions(options)) mux.Get("/path/{value}", stdhttp.HandlerFunc(func(w stdhttp.ResponseWriter, r *stdhttp.Request) {