Documentation
¶
Overview ¶
Package clientip provides client IP helpers. Package clientip 提供客户端 IP 辅助函数。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromRemote ¶
FromRemote parses an IP from remoteAddr. FromRemote 从 remoteAddr 解析 IP。
func FromRequest ¶
FromRequest returns the client IP for r. Call FromRequest(r, Options{TrustedProxies: ...}) when forwarded headers are trusted. FromRequest 返回 r 的客户端 IP。 需要信任转发头时,调用 FromRequest(r, Options{TrustedProxies: ...})。
Example / 示例:
ip, ok := clientip.FromRequest(r, clientip.Options{})
Types ¶
type Options ¶
type Options struct {
TrustedProxies []netip.Prefix
// Headers lists accepted client IP headers in priority order.
// Nil uses X-Forwarded-For, X-Real-IP, Forwarded, True-Client-IP, then CF-Connecting-IP.
// An empty non-nil slice disables forwarded headers. Other names accept a single IP.
// Headers 按优先级列出接受的客户端 IP 头。
// Nil 依次使用 X-Forwarded-For、X-Real-IP、Forwarded、True-Client-IP、CF-Connecting-IP。
// 非 nil 空切片禁用转发头。其他头名称按单个 IP 解析。
Headers []string
}
Options configures forwarded-header trust. Options 配置转发头信任边界。
Click to show internal directories.
Click to hide internal directories.