Documentation
¶
Index ¶
- Variables
- func FormDataDecode[T any](r *http.Request, sizes ...int64) (*T, error)
- func FormDecode(r *http.Request, dst any) error
- func GetHeaderValueFormatInt(header http.Header, fields ...string) (map[string]int, error)
- func GetQueryValueFromQuery2Int(qs url.Values, fields string, defaultValue ...int) (int, bool)
- func GetQueryValueFromRequest2Int(r *http.Request, fields string, defaultValue ...int) (int, bool)
- func Getip(r *http.Request, policys ...IPSource) string
- func JsonDecode[T any](r *http.Request) (T, error)
- func JsonDecodePtr[T interface{ ... }, E any](r *http.Request, target ...T) (T, error)
- func QueryDecode(u url.Values, dst any) error
- type File
- type Files
- type IPParsePolicy
- type IPSource
- type IPSources
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultIPSourcePriority = []IPSource{ HeaderTrueClientIP, HeaderCFConnectingIP, HeaderXRealIP, HeaderForwarded, HeaderXForwardedFor, HeaderHTTPXForwardedFor, HeaderHTTPClientIP, RemoteAddr, }
DefaultIPSourcePriority 默认IP来源解析顺序(按可信度从高到低)
Functions ¶
func FormDecode ¶
FormDecode 解析 application/x-www-form-urlencoded 编码的 form 数据
func GetHeaderValueFormatInt ¶
GetHeaderValueFormatInt 获取多个header字段,并转为int
func JsonDecode ¶
JsonDecode 解析json数据 值类型,适合小结构体,当字段少于10的时候,缺点是返回时会复制整个结构体
func JsonDecodePtr ¶
JsonDecodePtr 解析json数据 处理指针类型(调用方需确保T是指针类型,如 *YourStruct)
Types ¶
type IPParsePolicy ¶
type IPParsePolicy []IPSource
func (IPParsePolicy) GetFromIPSources ¶
func (p IPParsePolicy) GetFromIPSources(sources *IPSources) string
type IPSource ¶
type IPSource string
const ( RemoteAddr IPSource = "RemoteAddr" //noinspection no 标准或广泛使用的头部 HeaderForwarded IPSource = "Forwarded" // RFC 7239 HeaderXForwardedFor IPSource = "X-Forwarded-For" // 事实标准 HeaderXRealIP IPSource = "X-Real-IP" // Nginx等 HeaderCFConnectingIP IPSource = "CF-Connecting-IP" // CloudFlare HeaderTrueClientIP IPSource = "True-Client-IP" // Akamai等 //noinspection no 常见但非标准的变体(保持向后兼容) HeaderHTTPClientIP IPSource = "HTTP_CLIENT_IP" HeaderHTTPXForwardedFor IPSource = "HTTP_X_FORWARDED_FOR" HeaderXForwardedHost IPSource = "X-Forwarded-Host" HeaderXForwardedProto IPSource = "X-Forwarded-Proto" //noinspection no 特殊代理头部 HeaderVia IPSource = "Via" // 代理服务器链 )
IPHeader 定义标准的HTTP头部字段名 noinspection no
type IPSources ¶
type IPSources struct {
RemoteAddr string `json:"remote_addr"` // 直接连接信息
// 标准头部
Forwarded string `json:"forwarded,omitempty"` // RFC 7239
XForwardedFor string `json:"x_forwarded_for,omitempty"` // 事实标准
XRealIP string `json:"x_real_ip,omitempty"` // Nginx等
CFConnectingIP string `json:"cf_connecting_ip,omitempty"` // CloudFlare
TrueClientIP string `json:"true_client_ip,omitempty"` // Akamai等
// 非标准变体(向后兼容)
HTTPClientIP string `json:"http_client_ip,omitempty"`
HTTPXForwardedFor string `json:"http_x_forwarded_for,omitempty"`
// 其他相关头部
XForwardedHost string `json:"x_forwarded_host,omitempty"`
XForwardedProto string `json:"x_forwarded_proto,omitempty"`
Via string `json:"via,omitempty"`
}
func ParseRequestIPSources ¶
ParseRequestIPSources 解析请求中的所有IP相关信息
Click to show internal directories.
Click to hide internal directories.