package eia import ( "context" "errors" "net/http" "time" "github.com/rs/zerolog" eiaapi "gitea.libretechconsulting.com/rmcguire/eia-api-go/api" ) func newLoggingMiddleware(logger *zerolog.Logger, level zerolog.Level) eiaapi.RequestEditorFn { return func(_ context.Context, req *http.Request) error { if req == nil { return errors.New("invalid nil http request") } else if req.URL == nil { return errors.New("missing request url") } else if req.Method == "" { return errors.New("missing request method") } // Don't log api_key params := req.URL.Query() delete(params, "api_key") logger.WithLevel(level). Str("method", req.Method). Str("host", req.URL.Host). Str("path", req.URL.Path). Str("query", params.Encode()). Time("timestamp", time.Now()). Send() return nil } }