Skip to content

natureglobal/realip

Folders and files

NameName
Last commit message
Last commit date
Apr 7, 2020
Apr 7, 2020
Feb 17, 2021
Apr 7, 2020
Apr 7, 2020
Apr 8, 2020
Apr 8, 2020
Apr 8, 2020
Feb 17, 2021
Apr 8, 2020
Feb 17, 2021

Repository files navigation

realip

Test Status Coverage Status MIT License GoDoc

The realip detects client real ip in Go's HTTP middleware layer.

Synopsis

_, ipnet, _ := net.ParseCIDR("192.168.0.0/16")
var middleware func(http.Handler) http.Handler = realip.MustMiddleware(&realip.Config{
    RealIPFrom:      []*net.IPNet{ipnet},
    RealIPHeader:    realip.HeaderXForwardedFor,
    RealIPRecursive: true,
})
var handler http.HandlerFunc = func(w http.ResponseWriter, req *http.Request) {
    fmt.Fprintf(w, req.Header.Get("X-Real-IP"))
})
handler = middleware(handler)

Description

The realip package implements detecting client real IP mechanisms from request headers in Go's HTTP middleware layer.

This realizes the similar function as Nginx's ngx_http_realip_module in the layer inside Go. Therefore, the setting property names and behaviors are also close to ngx_http_realip_module.

The realip provides Go's HTTP Middleware. It detects the client's real ip from the request and sets it in the specified request header (Default: X-Real-IP).

Installation

% go get github.com/natureglobal/realip

Author

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published