Documentation
¶
Index ¶
- func AcceptsHTML(c *gin.Context) bool
- func AcceptsJSON(c *gin.Context) bool
- func Bind(c *gin.Context, i any) error
- func BindJSON(c *gin.Context, i any) error
- func BindQuery(c *gin.Context, i any) error
- func BindUri(c *gin.Context, i any) error
- func File(c *gin.Context, key string) *multipart.FileHeader
- func Files(c *gin.Context, key string) []*multipart.FileHeader
- func GetBearerToken(c *gin.Context) string
- func GetClientIP(c *gin.Context) string
- func GetFullURL(c *gin.Context) string
- func GetHost(c *gin.Context) string
- func GetMethod(c *gin.Context) string
- func GetReferer(c *gin.Context) string
- func GetScheme(c *gin.Context) string
- func GetUserAgent(c *gin.Context) string
- func Input[T InputType](c *gin.Context, key string, defaultValue ...T) T
- func IsAjax(c *gin.Context) bool
- func IsDELETE(c *gin.Context) bool
- func IsFormData(c *gin.Context) bool
- func IsGET(c *gin.Context) bool
- func IsJSON(c *gin.Context) bool
- func IsLocalIP(ip string) bool
- func IsMethod(c *gin.Context, method string) bool
- func IsMobile(c *gin.Context) bool
- func IsMultipartForm(c *gin.Context) bool
- func IsPATCH(c *gin.Context) bool
- func IsPOST(c *gin.Context) bool
- func IsPUT(c *gin.Context) bool
- func IsSecure(c *gin.Context) bool
- func IsXML(c *gin.Context) bool
- type InputType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Files ¶
func Files(c *gin.Context, key string) []*multipart.FileHeader
Files 获取同名的多个上传文件,不存在时返回 nil
func GetBearerToken ¶
GetBearerToken 从 Authorization 头获取 Bearer Token
func GetClientIP ¶
GetClientIP 获取客户端真实 IP 地址。 委托给 gin.Context.ClientIP(),由其依据可信代理(TrustedProxies)配置安全地解析 X-Forwarded-For/X-Real-IP;不再直接信任可被伪造的转发头。
func Input ¶
Input 按 key 读取请求参数并转换为目标类型 T,缺失或解析失败时返回默认值。
取值优先级:POST 表单 > Query > URL 路径参数(见 getRawValue / getArrayValues)。 注意:不读取 JSON 请求体;JSON 请求请使用 BindJSON 绑定到结构体。
支持的类型:
- 基本类型: string, int, int64, float32, float64, bool
- 数组类型: []string, []int, []int64
文件上传请使用 File / Files。
使用示例:
name := request.Input(c, "name", "默认名称") // string
age := request.Input(c, "age", 18) // int
price := request.Input(c, "price", 9.99) // float64
active := request.Input(c, "active", true) // bool
tags := request.Input(c, "tags", []string{}) // []string
ids := request.Input(c, "ids", []int{}) // []int
func IsMultipartForm ¶
IsMultipartForm 判断是否为 multipart/form-data 请求
Types ¶
Click to show internal directories.
Click to hide internal directories.