17 lines
432 B
Go
17 lines
432 B
Go
|
|
package middleware
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"warpbox.dev/backend/libs/services"
|
||
|
|
)
|
||
|
|
|
||
|
|
func ClientIP(trustedProxies []string) Middleware {
|
||
|
|
return func(next http.Handler) http.Handler {
|
||
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
ip := services.ClientIP(r.RemoteAddr, r.Header.Get("X-Forwarded-For"), r.Header.Get("X-Real-IP"), trustedProxies)
|
||
|
|
next.ServeHTTP(w, services.WithClientIP(r, ip))
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|