From 0e597412ed9a544075bd279bd09c7c2f3b7dc529 Mon Sep 17 00:00:00 2001 From: Dmitry Savintsev Date: Wed, 27 Sep 2023 22:55:25 +0200 Subject: [PATCH] use const 'pingPath' consistently --- pkg/generated/restapi/configure_timestamp_server.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/generated/restapi/configure_timestamp_server.go b/pkg/generated/restapi/configure_timestamp_server.go index 59274d017..c602b8126 100644 --- a/pkg/generated/restapi/configure_timestamp_server.go +++ b/pkg/generated/restapi/configure_timestamp_server.go @@ -103,16 +103,17 @@ func (l *logAdapter) Print(v ...interface{}) { log.Logger.Info(v...) } +const pingPath = "/ping" + // httpPingOnly custom middleware prohibits all entrypoints except // "/ping" on the http (non-HTTPS) server. func httpPingOnly() func(http.Handler) http.Handler { - const pingpath = "/ping" f := func(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { - if r.URL.Scheme != "https" && !strings.EqualFold(r.URL.Path, pingpath) { + if r.URL.Scheme != "https" && !strings.EqualFold(r.URL.Path, pingPath) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusNotFound) - w.Write([]byte("http server supports only the " + pingpath + " entrypoint")) //nolint:errcheck + w.Write([]byte("http server supports only the " + pingPath + " entrypoint")) //nolint:errcheck return } h.ServeHTTP(w, r) @@ -129,7 +130,7 @@ func setupGlobalMiddleware(handler http.Handler) http.Handler { &middleware.DefaultLogFormatter{Logger: &logAdapter{}}) returnHandler := middleware.Logger(handler) returnHandler = middleware.Recoverer(returnHandler) - returnHandler = middleware.Heartbeat("/ping")(returnHandler) + returnHandler = middleware.Heartbeat(pingPath)(returnHandler) if cmdparams.IsHTTPPingOnly { returnHandler = httpPingOnly()(returnHandler) }