From df75d1149974377ba5d7851e26bf3c9db20e7eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Wysoki=C5=84ski?= Date: Fri, 12 May 2023 06:56:51 +0200 Subject: [PATCH] fix: fix linter errors --- client_ip.go | 4 ++-- client_ip_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client_ip.go b/client_ip.go index bb25dda..cc05011 100644 --- a/client_ip.go +++ b/client_ip.go @@ -11,10 +11,10 @@ type clientIPCtxKey struct{} // ClientIP is a go-chi middleware that derives the client IP from realclientip.Strategy // and stores it in the http.Request Context. -func ClientIP(strat realclientip.Strategy) func(next http.Handler) http.Handler { +func ClientIP(strategy realclientip.Strategy) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - clientIP := strat.ClientIP(r.Header, r.RemoteAddr) + clientIP := strategy.ClientIP(r.Header, r.RemoteAddr) r = r.WithContext(context.WithValue(r.Context(), clientIPCtxKey{}, clientIP)) next.ServeHTTP(w, r) }) diff --git a/client_ip_test.go b/client_ip_test.go index ad5bb66..cd132af 100644 --- a/client_ip_test.go +++ b/client_ip_test.go @@ -25,9 +25,10 @@ func TestClientIP(t *testing.T) { { name: "OK: X-Forwarded-For", strategy: func(t *testing.T) realclientip.Strategy { - strat, err := realclientip.NewRightmostNonPrivateStrategy(http.CanonicalHeaderKey("X-Forwarded-For")) + t.Helper() + strategy, err := realclientip.NewRightmostNonPrivateStrategy(http.CanonicalHeaderKey("X-Forwarded-For")) require.NoError(t, err) - return strat + return strategy }, remoteAddr: "192.0.2.1:1234", header: func(header http.Header) http.Header { @@ -39,6 +40,7 @@ func TestClientIP(t *testing.T) { { name: "OK: X-Forwarded-For, RemoteAddr", strategy: func(t *testing.T) realclientip.Strategy { + t.Helper() stratXForwardedFor, err := realclientip.NewRightmostNonPrivateStrategy(http.CanonicalHeaderKey("X-Forwarded-For")) require.NoError(t, err) return realclientip.NewChainStrategy(