Documentation ¶
Index ¶
- Variables
- func AuthByDataPacketFuncHandler(f ToAuthDataPacketFunc) gin.HandlerFunc
- func AuthHandler(jwtAuth interfaces.ItfJwtParser) gin.HandlerFunc
- func CorsHandler(corsConfig ...cors.Config) gin.HandlerFunc
- func GetAuth(ctx *gin.Context) dto.AuthInfo
- func GetAuthDataPacket(ctx *gin.Context) *dto.AuthDataPacket
- func GetOperateLog(ctx *gin.Context) (string, bool)
- func HealthHandler(ctx *gin.Context)
- func MatchMethodHandler(methods ...string) gin.HandlerFunc
- func NewTestAuthContext() (*gin.Context, *httptest.ResponseRecorder)
- func NewTestContext() (*gin.Context, *httptest.ResponseRecorder)
- func OptionRequestHandler() gin.HandlerFunc
- func PanicHandler(ctx *gin.Context)
- func PingHandler(ctx *gin.Context)
- func QPSLimiterHandler(r rate.Limit, b int) gin.HandlerFunc
- func Response(ctx *gin.Context, data respdata.ResponseData, msgData ...map[string]string)
- func ResponseCode(ctx *gin.Context, code int, data respdata.ResponseData, ...)
- func ResponseError(ctx *gin.Context, err error)
- func SetAuth(ctx *gin.Context, auth *dto.AuthDataPacket)
- func SetOperateLog(ctx *gin.Context, log ...string)
- type AccreditOption
- type AuthOption
- type CaptchaController
- func (ctr *CaptchaController) CaptchaDriver() base64Captcha.Driver
- func (ctr *CaptchaController) CaptchaStore() base64Captcha.Store
- func (ctr *CaptchaController) GetCaptcha(ctx *gin.Context)
- func (ctr *CaptchaController) VerifyCaptcha(ctx *gin.Context)
- func (ctr *CaptchaController) VerifyHandler() gin.HandlerFunc
- type CorsOption
- type HandlerOption
- type I18nController
- type OperateLogController
- type OperateLogOption
- type PProfOption
- type ResponseController
- type SwaggerOption
- type ToAuthDataPacketFunc
Constants ¶
This section is empty.
Variables ¶
var AddRequestIdHandler = func(requestIdField string) gin.HandlerFunc { return func(ctx *gin.Context) { ctx.Set("request_id", utils.NewRequestId()) } }
AddRequestIdHandler 添加requestId
Functions ¶
func AuthByDataPacketFuncHandler ¶
func AuthByDataPacketFuncHandler(f ToAuthDataPacketFunc) gin.HandlerFunc
AuthByDataPacketFuncHandler 指定DataPacket解析func的auth handler
func AuthHandler ¶
func AuthHandler(jwtAuth interfaces.ItfJwtParser) gin.HandlerFunc
AuthHandler 授权处理handler
func CorsHandler ¶
func CorsHandler(corsConfig ...cors.Config) gin.HandlerFunc
CorsHandler 跨域handler
func GetAuthDataPacket ¶
func GetAuthDataPacket(ctx *gin.Context) *dto.AuthDataPacket
GetAuthDataPacket 获取存储的auth数据包
func MatchMethodHandler ¶
func MatchMethodHandler(methods ...string) gin.HandlerFunc
MatchMethodHandler 请求方法匹配
func NewTestAuthContext ¶
func NewTestAuthContext() (*gin.Context, *httptest.ResponseRecorder)
NewTestAuthContext 测试用gin.context
func NewTestContext ¶
func NewTestContext() (*gin.Context, *httptest.ResponseRecorder)
NewTestContext 测试用gin.context, 默认post请求,可自行修改
func OptionRequestHandler ¶
func OptionRequestHandler() gin.HandlerFunc
OptionRequestHandler OPTION请求过滤
func QPSLimiterHandler ¶
func QPSLimiterHandler(r rate.Limit, b int) gin.HandlerFunc
QPSLimiterHandler qps限流处理, r:1秒内平均速率,b:1秒内最大允许突发流量
func ResponseCode ¶
func ResponseError ¶
Types ¶
type AccreditOption ¶
type AccreditOption struct {
AccreditHandler gin.HandlerFunc //指定权限校验Handler
}
AccreditOption 授权验证选项
func (*AccreditOption) OptAccreditHandler ¶
func (s *AccreditOption) OptAccreditHandler(defaults ...gin.HandlerFunc) gin.HandlerFunc
type AuthOption ¶
type AuthOption struct { AuthHandler gin.HandlerFunc //指定authHandler AuthPacketFunc ToAuthDataPacketFunc //指定解析dataPacket的func }
AuthOption 身份验证相关选项
func (*AuthOption) OptAuthHandler ¶
func (s *AuthOption) OptAuthHandler(defaults ...gin.HandlerFunc) gin.HandlerFunc
type CaptchaController ¶
type CaptchaController struct { Store base64Captcha.Store Driver *base64Captcha.DriverDigit Di *dig.Container }
CaptchaController 验证码图片相关Controller
func NewCaptchaController ¶
func NewCaptchaController(di *dig.Container) *CaptchaController
func (*CaptchaController) CaptchaDriver ¶
func (ctr *CaptchaController) CaptchaDriver() base64Captcha.Driver
func (*CaptchaController) CaptchaStore ¶
func (ctr *CaptchaController) CaptchaStore() base64Captcha.Store
func (*CaptchaController) GetCaptcha ¶
func (ctr *CaptchaController) GetCaptcha(ctx *gin.Context)
func (*CaptchaController) VerifyCaptcha ¶
func (ctr *CaptchaController) VerifyCaptcha(ctx *gin.Context)
func (*CaptchaController) VerifyHandler ¶
func (ctr *CaptchaController) VerifyHandler() gin.HandlerFunc
type HandlerOption ¶
type HandlerOption struct {
Handler gin.HandlerFunc //指定权限校验Handler
}
HandlerOption 通用handler选项配置
func (HandlerOption) OptHandler ¶
func (s HandlerOption) OptHandler(defaults ...gin.HandlerFunc) gin.HandlerFunc
type I18nController ¶
type I18nController struct { Parser i18n.II18nParser ErrIgnoreLog bool //错误返回是否忽略日志 }
I18nController i18n国际化Controller
func (*I18nController) Response ¶
func (ctr *I18nController) Response(ctx *gin.Context, data respdata.ResponseData, msgData ...map[string]string)
func (*I18nController) ResponseCode ¶
func (ctr *I18nController) ResponseCode(ctx *gin.Context, code int, data respdata.ResponseData, msgData ...map[string]string)
type OperateLogController ¶
type OperateLogController struct { }
OperateLogController 操作日志控制器
func (*OperateLogController) CustomizeLog ¶
func (ctr *OperateLogController) CustomizeLog(ctx *gin.Context, log string)
CustomizeLog 指定记录操作日志
type OperateLogOption ¶
type OperateLogOption struct {
OperateLogHandler gin.HandlerFunc //指定日志记录的handler
}
OperateLogOption 操作日志选项
func (OperateLogOption) OptLogHandler ¶
func (opt OperateLogOption) OptLogHandler(defaults ...gin.HandlerFunc) gin.HandlerFunc
func (OperateLogOption) RecordLog ¶
func (opt OperateLogOption) RecordLog(s ...string) gin.HandlerFunc
type PProfOption ¶
type PProfOption struct { Enable bool `json:"Enable" yaml:"Enable"` Port int64 `json:"Port" yaml:"Port"` //用于pprof的端口号,如: 8808 }
PProfOption pprof支持选项
func (PProfOption) PProfRouter ¶
func (s PProfOption) PProfRouter(r *gin.Engine)
PProfRouter 注册路由,注册必须为gin.Engine,防止有前缀
type ResponseController ¶
type ResponseController struct {
ErrIgnoreLog bool //错误返回是否忽略日志
}
ResponseController 返回Controller
func (*ResponseController) Response ¶
func (ctr *ResponseController) Response(ctx *gin.Context, data respdata.ResponseData, msgData ...map[string]string)
func (*ResponseController) ResponseCode ¶
func (ctr *ResponseController) ResponseCode(ctx *gin.Context, code int, data respdata.ResponseData, msgData ...map[string]string)
type SwaggerOption ¶
type SwaggerOption struct { Enable bool `json:"enable"` Name string `json:"name"` Path string `json:"path"` //指定路由路径 Swagger *swag.Spec }
SwaggerOption 支持swagger
func (SwaggerOption) SwaggerDocsPath ¶
func (s SwaggerOption) SwaggerDocsPath() string
SwaggerDocsPath swagger docs访问地址
func (SwaggerOption) SwaggerRouter ¶
func (s SwaggerOption) SwaggerRouter(g gin.IRouter)
SwaggerRouter 注册swagger路由 访问地址: http://127.0.0.1:10000/swagger/{{Name}}/doc.json
func (SwaggerOption) SwaggerRouterPath ¶
func (s SwaggerOption) SwaggerRouterPath() string
SwaggerRouterPath swagger路由地址
type ToAuthDataPacketFunc ¶
type ToAuthDataPacketFunc func(ctx *gin.Context) (*dto.AuthDataPacket, error)
func ParseAuthByJwtFunc ¶
func ParseAuthByJwtFunc(jwtAuth interfaces.ItfJwtParser) ToAuthDataPacketFunc
ParseAuthByJwtFunc jwt解析auth的function