fix: fix linter errors
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
dffece5411
commit
df75d11499
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue