Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientIP ¶
ClientIP 使用默认配置获取客户端真实IP RemoteIP 为服务端收到客户端连接时识别到的IP地址,但受限于复杂的网络环境,客户端可能使用代理服务,RemoteIP拿到的只是代理服务器IP 通常代理服务会在HTTP Header 中追加客户端IP地址,通过读取该Header获取客户端ip 同时,代理服务可以设置任意IP,所以对于不信任的代理服务器,可能获取到伪造IP,使用 NewIPValidator 可自定义解析策略
func FigureOutListenOn ¶
func GetMacAddress ¶
Types ¶
type IPValidator ¶
type IPValidator struct {
// contains filtered or unexported fields
}
func NewIPValidator ¶
func NewIPValidator(options ...IPValidatorOption) *IPValidator
func (*IPValidator) ClientIP ¶
func (v *IPValidator) ClientIP(r *http.Request) string
ClientIP implements one best effort algorithm to return the real client IP. It calls c.RemoteIP() under the hood, to check if the remote IP is a trusted proxy or not. If it is it will then try to parse the headers defined in Engine.RemoteIPHeaders (defaulting to [X-Forwarded-For, X-Real-Ip]). If the headers are not syntactically valid OR the remote IP does not correspond to a trusted proxy, the remote IP (coming from Request.RemoteAddr) is returned.
type IPValidatorOption ¶
type IPValidatorOption func(v *IPValidator)
func WithForwardedByClientIP ¶
func WithForwardedByClientIP(forwardedByClientIP bool) IPValidatorOption
func WithRemoteIPHeaders ¶
func WithRemoteIPHeaders(remoteIPHeaders []string) IPValidatorOption
func WithTrustedPlatform ¶
func WithTrustedPlatform(trustedPlatform string) IPValidatorOption
func WithTrustedProxies ¶
func WithTrustedProxies(proxies []string) IPValidatorOption