Documentation
¶
Index ¶
- Variables
- func Error(c *gin.Context, code int, message string)
- func GetRealIP(c *gin.Context, useCDN bool) (realIP string)
- func GetRealIPWithFilter(c *gin.Context, useCDN bool, whitelist, blacklist []string) (realIP string)
- func JSON(c *gin.Context, code int, message string, data interface{})
- func Success(c *gin.Context, data interface{}, opts ...Option)
- type Base
- type Option
- type Options
- type Response
Constants ¶
This section is empty.
Variables ¶
View Source
var WithEncryptID = serializer.WithEncryptID
WithEncryptID 注入 ID 加密函数。
View Source
var WithFormatTime = serializer.WithFormatTime
WithFormatTime 注入时间值格式化函数。
View Source
var WithIDField = serializer.WithIDField
WithIDField 注入 ID 字段判断函数。
View Source
var WithMaxDepth = serializer.WithMaxDepth
WithMaxDepth 注入递归处理最大深度。
View Source
var WithSkipField = serializer.WithSkipField
WithSkipField 注入字段跳过判断函数。
View Source
var WithTimeField = serializer.WithTimeField
WithTimeField 注入时间字段判断函数。
Functions ¶
func GetRealIP ¶ added in v0.13.3
GetRealIP 获取真实客户端IP地址 当useCDN为true时,优先从代理头信息中获取IP;为false时,直接使用gin的ClientIP方法 参数:
- c: gin上下文
- useCDN: 是否使用CDN或代理,true表示使用,false表示不使用
返回值:
- realIP: 真实客户端IP地址
func GetRealIPWithFilter ¶ added in v0.13.5
func GetRealIPWithFilter(c *gin.Context, useCDN bool, whitelist, blacklist []string) (realIP string)
GetRealIPWithFilter 获取真实客户端IP地址(带过滤功能) 参数:
- c: gin上下文
- useCDN: 是否使用CDN或代理,true表示使用,false表示不使用
- whitelist: IP白名单列表,如果提供则只允许白名单内的IP
- blacklist: IP黑名单列表,如果提供则拒绝黑名单内的IP
返回值:
- realIP: 真实客户端IP地址
Types ¶
type Base ¶
type Base struct {
}
func (Base) SetGPC ¶
func (b Base) SetGPC(e *gin.Engine) gin.HandlerFunc
SetGPC 把 query、cookie、header 与请求体参数汇总到上下文的 "GPC" 键 请求体按 Content-Type 分派解析,读到的字节一律回灌,业务 handler 仍可重复读取原始请求体 参数:
- e: gin 引擎,取用其 MaxMultipartMemory 作为 multipart 的内存上限
返回值:
- gin.HandlerFunc: 注册到引擎的中间件
异常:不触发 panic;请求体解析失败只记录日志并给出空的 data,GPC 结构始终完整写入 使用示例:
base := middleware.Base{}
e := gin.Default()
e.Use(base.SetGPC(e))
type Options ¶ added in v0.13.24
type Options = serializer.Options
Options 为序列化处理选项的别名,保持与原有 middleware 调用方式一致。
Click to show internal directories.
Click to hide internal directories.