fix: fix linter errors
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dawid Wysokiński 2023-05-12 06:56:51 +02:00
parent dffece5411
commit df75d11499
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
2 changed files with 6 additions and 4 deletions

View File

@ -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)
})

View File

@ -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(