gin_http

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 GetAuth

func GetAuth(ctx *gin.Context) dto.AuthInfo

GetAuth 获取auth信息

func GetAuthDataPacket

func GetAuthDataPacket(ctx *gin.Context) *dto.AuthDataPacket

GetAuthDataPacket 获取存储的auth数据包

func GetOperateLog

func GetOperateLog(ctx *gin.Context) (string, bool)

GetOperateLog 获取操作日志,返回:

log,日志内容
ok,是否需要记录

func HealthHandler

func HealthHandler(ctx *gin.Context)

HealthHandler 健康检查处理方法

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 PanicHandler

func PanicHandler(ctx *gin.Context)

PanicHandler panic处理

func PingHandler

func PingHandler(ctx *gin.Context)

PingHandler ping处理handler

func QPSLimiterHandler

func QPSLimiterHandler(r rate.Limit, b int) gin.HandlerFunc

QPSLimiterHandler qps限流处理, r:1秒内平均速率,b:1秒内最大允许突发流量

func Response

func Response(ctx *gin.Context, data respdata.ResponseData, msgData ...map[string]string)

func ResponseCode

func ResponseCode(ctx *gin.Context, code int, data respdata.ResponseData, msgData ...map[string]string)

func ResponseError

func ResponseError(ctx *gin.Context, err error)

func SetAuth

func SetAuth(ctx *gin.Context, auth *dto.AuthDataPacket)

SetAuth 设置auth信息

func SetOperateLog

func SetOperateLog(ctx *gin.Context, log ...string)

SetOperateLog 手动配置操作日志

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 CorsOption

type CorsOption struct {
	NoCors bool //不处理跨域
}

CorsOption 跨域相关选项

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,防止有前缀

func (PProfOption) Start

func (s PProfOption) Start() error

Start 开始

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL