Documentation
¶
Index ¶
- Constants
- func GetClientInfo(ctx *gin.Context) (res *cljent.ClientInfo)
- func Middleware(handle internal.MiddlewareHandleFunc, priorities ...int) internal.Middleware
- func New(opts []Option) *internal.Server
- func OnExit(fn func()) internal.Option
- func OnResponded(fn func(ctx context.Context, data *RequestResponseData)) internal.Option
- func OnShutdown(fn func()) internal.Option
- func OnStart(fn func()) internal.Option
- func OnStartFail(fn func(error)) internal.Option
- func Response(ctx *gin.Context, data any, err error, opts ...internal.ResponseOption)
- func ResponseError(ctx *gin.Context, err error, opts ...internal.ResponseOption)
- func ResponseOptionCode(code int64) internal.ResponseOption
- func ResponseOptionData(data any) internal.ResponseOption
- func ResponseOptionMsg(msg string) internal.ResponseOption
- func ResponseOptionTypeAsciiJSON() internal.ResponseOption
- func ResponseOptionTypeHTML() internal.ResponseOption
- func ResponseOptionTypeJSON() internal.ResponseOption
- func ResponseOptionTypeJSONP() internal.ResponseOption
- func ResponseOptionTypeStream() internal.ResponseOption
- func ResponseSuccess(ctx *gin.Context, data any, opts ...internal.ResponseOption)
- func ResponseWithStatus(ctx *gin.Context, status int, opts ...internal.ResponseOption)
- func SetupVerifyCSRFToken(eng *gin.Engine, opts ...CSRFOption) gin.HandlerFunc
- func WrapEngineMiddleware(handle gin.HandlerFunc, priorities ...int) internal.Middleware
- type CSRFConfig
- type CSRFOption
- func CSRFOptionCookieKey(s string) CSRFOption
- func CSRFOptionCookiePath(s string) CSRFOption
- func CSRFOptionCrypter(crypter *crypto.AESGCMCrypter) CSRFOption
- func CSRFOptionDomain(s string) CSRFOption
- func CSRFOptionErLog(e erlogs.ErLogInterface) CSRFOption
- func CSRFOptionHeaderCTKey(s string) CSRFOption
- func CSRFOptionHeaderCVKey(s string) CSRFOption
- func CSRFOptionHeaderDidKey(s string) CSRFOption
- func CSRFOptionHeaderExpireKey(s string) CSRFOption
- func CSRFOptionHeaderKey(s string) CSRFOption
- func CSRFOptionHeaderRequestIdKey(s string) CSRFOption
- func CSRFOptionMaxAge(i int) CSRFOption
- func CSRFOptionMethods(ss ...string) CSRFOption
- func CSRFOptionOrigins(ss ...string) CSRFOption
- func CSRFOptionRefererPrefixs(ss ...string) CSRFOption
- func CSRFOptionVerify(f func(ctx *gin.Context) bool) CSRFOption
- type ContextResponse
- func (r *ContextResponse) Response(data any, err error, opts ...internal.ResponseOption)
- func (r *ContextResponse) ResponseError(err error, opts ...internal.ResponseOption)
- func (r *ContextResponse) ResponseSuccess(data any, opts ...internal.ResponseOption)
- func (r *ContextResponse) ResponseWithStatus(status int, opts ...internal.ResponseOption)
- type Option
- func Defers(defers ...internal.Defer) Option
- func HammerTime(s string) Option
- func IdleTimeout(s string) Option
- func Inits(inits ...internal.Init) Option
- func KeepAlive(b bool) Option
- func LoggerHeaderKeys(keys ...string) Option
- func Middlewares(middlewares ...internal.Middleware) Option
- func Port(i int) Option
- func ReadHeaderTimeout(s string) Option
- func ReadTimeout(s string) Option
- func Routes(routes ...internal.Route) Option
- func TLSKeyCert(s string) Option
- func TLSKeyFile(s string) Option
- func TLSOpen(b bool) Option
- func WriteTimeout(s string) Option
- type PriorityMiddleware
- type RequestResponseData
- type Route
Constants ¶
const ( DidLength = 32 CSRFTokenCookieName = "X-Song-Csrf-Token" CSRFTokenHeaderName = "X-Song-Csrf-Token" CSRFTokenExpireHeaderName = "X-Song-Csrf-Token-Expire" ClientRequestIdHeaderName = "X-Song-Request-Id" ClientDidHeaderName = "X-Song-Did" ClientCTHeaderName = "X-Song-Ct" ClientCVHeaderName = "X-Song-Cv" )
const (
ClientInfoContextKey = "X-Song-Client-Info"
)
Variables ¶
This section is empty.
Functions ¶
func GetClientInfo ¶
func GetClientInfo(ctx *gin.Context) (res *cljent.ClientInfo)
GetClientInfo 获取客户端信息
func Middleware ¶
func Middleware(handle internal.MiddlewareHandleFunc, priorities ...int) internal.Middleware
Middleware 返回可自定义优先级的中间件 可自定义优先级,默认优先级999(priorities仅取第一个作为中间件优先级)
func OnResponded ¶
func OnResponded(fn func(ctx context.Context, data *RequestResponseData)) internal.Option
OnResponded 请求响应完成后执行(请求日志已记录)
func OnShutdown ¶
func OnStartFail ¶
func Response ¶
Response 请求响应。 @Param data any 响应数据 @param err error 请求错误。成功时,nil或者级别低于warning的错误;失败时,不为nil且级别高于warning的错误 @Param opts []inetrnal.ResponseOption 自定义响应选项,可覆盖默认根据err和data设定的选项
func ResponseError ¶
func ResponseError(ctx *gin.Context, err error, opts ...internal.ResponseOption)
ResponseError 请求失败(发生错误或异常)时的响应 @param err error 请求错误。成功时,nil或者级别低于warning的错误;失败时,不为nil且级别高于warning的错误 @Param opts []inetrnal.ResponseOption 自定义响应选项,可覆盖默认根据data设定的选项
func ResponseOptionCode ¶
func ResponseOptionCode(code int64) internal.ResponseOption
func ResponseOptionData ¶
func ResponseOptionData(data any) internal.ResponseOption
func ResponseOptionMsg ¶
func ResponseOptionMsg(msg string) internal.ResponseOption
func ResponseOptionTypeAsciiJSON ¶
func ResponseOptionTypeAsciiJSON() internal.ResponseOption
func ResponseOptionTypeHTML ¶
func ResponseOptionTypeHTML() internal.ResponseOption
func ResponseOptionTypeJSON ¶
func ResponseOptionTypeJSON() internal.ResponseOption
func ResponseOptionTypeJSONP ¶
func ResponseOptionTypeJSONP() internal.ResponseOption
func ResponseOptionTypeStream ¶
func ResponseOptionTypeStream() internal.ResponseOption
func ResponseSuccess ¶
func ResponseSuccess(ctx *gin.Context, data any, opts ...internal.ResponseOption)
ResponseSuccess 请求成功时的响应 @param data any 响应数据 @Param opts []inetrnal.ResponseOption 自定义响应选项,可覆盖默认根据data设定的选项
func ResponseWithStatus ¶
func ResponseWithStatus(ctx *gin.Context, status int, opts ...internal.ResponseOption)
ResponseWithStatus 自定义http status响应,默认JSON格式
func SetupVerifyCSRFToken ¶
func SetupVerifyCSRFToken(eng *gin.Engine, opts ...CSRFOption) gin.HandlerFunc
SetupVerifyCSRFToken 设置&校验CSRF-Token
func WrapEngineMiddleware ¶
func WrapEngineMiddleware(handle gin.HandlerFunc, priorities ...int) internal.Middleware
Types ¶
type CSRFConfig ¶
type CSRFConfig struct {
Crypter *crypto.AESGCMCrypter
Verify func(ctx *gin.Context) bool
Erlog erlogs.ErLogInterface
Methods []string
Origins []string
RefererPrefixs []string
CookieKey string
HeaderKey string
HeaderExpireKey string
HeaderRequestIdKey string
HeaderDidKey string
HeaderCTKey string
HeaderCVKey string
Path string
Domain string
Secure bool
HttpOnly bool
MaxAge int
SameSite int64
}
type CSRFOption ¶
type CSRFOption struct {
Apply func(c *CSRFConfig)
}
func CSRFOptionCookieKey ¶
func CSRFOptionCookieKey(s string) CSRFOption
func CSRFOptionCookiePath ¶
func CSRFOptionCookiePath(s string) CSRFOption
func CSRFOptionCrypter ¶
func CSRFOptionCrypter(crypter *crypto.AESGCMCrypter) CSRFOption
func CSRFOptionDomain ¶
func CSRFOptionDomain(s string) CSRFOption
func CSRFOptionErLog ¶
func CSRFOptionErLog(e erlogs.ErLogInterface) CSRFOption
func CSRFOptionHeaderCTKey ¶
func CSRFOptionHeaderCTKey(s string) CSRFOption
func CSRFOptionHeaderCVKey ¶
func CSRFOptionHeaderCVKey(s string) CSRFOption
func CSRFOptionHeaderDidKey ¶
func CSRFOptionHeaderDidKey(s string) CSRFOption
func CSRFOptionHeaderExpireKey ¶
func CSRFOptionHeaderExpireKey(s string) CSRFOption
func CSRFOptionHeaderKey ¶
func CSRFOptionHeaderKey(s string) CSRFOption
func CSRFOptionHeaderRequestIdKey ¶
func CSRFOptionHeaderRequestIdKey(s string) CSRFOption
func CSRFOptionMaxAge ¶
func CSRFOptionMaxAge(i int) CSRFOption
func CSRFOptionMethods ¶
func CSRFOptionMethods(ss ...string) CSRFOption
func CSRFOptionOrigins ¶
func CSRFOptionOrigins(ss ...string) CSRFOption
func CSRFOptionRefererPrefixs ¶
func CSRFOptionRefererPrefixs(ss ...string) CSRFOption
func CSRFOptionVerify ¶
func CSRFOptionVerify(f func(ctx *gin.Context) bool) CSRFOption
type ContextResponse ¶
type ContextResponse struct {
// contains filtered or unexported fields
}
func WithContext ¶
func WithContext(ctx *gin.Context) *ContextResponse
func (*ContextResponse) Response ¶
func (r *ContextResponse) Response(data any, err error, opts ...internal.ResponseOption)
Response 请求响应。 @Param data any 响应数据 @param err error 请求错误。成功时,nil或者级别低于warning的错误;失败时,不为nil且级别高于warning的错误 @Param opts []inetrnal.ResponseOption 自定义响应选项,可覆盖默认根据err和data设定的选项
func (*ContextResponse) ResponseError ¶
func (r *ContextResponse) ResponseError(err error, opts ...internal.ResponseOption)
ResponseError 请求失败(发生错误或异常)时的响应 @param err error 请求错误。成功时,nil或者级别低于warning的错误;失败时,不为nil且级别高于warning的错误 @Param opts []inetrnal.ResponseOption 自定义响应选项,可覆盖默认根据data设定的选项
func (*ContextResponse) ResponseSuccess ¶
func (r *ContextResponse) ResponseSuccess(data any, opts ...internal.ResponseOption)
ResponseSuccess 请求成功时的响应 @param data any 响应数据 @Param opts []inetrnal.ResponseOption 自定义响应选项,可覆盖默认根据data设定的选项
func (*ContextResponse) ResponseWithStatus ¶
func (r *ContextResponse) ResponseWithStatus(status int, opts ...internal.ResponseOption)
ResponseWithStatus 自定义http status响应,默认JSON格式
type Option ¶
func HammerTime ¶
func IdleTimeout ¶
func LoggerHeaderKeys ¶
func ReadHeaderTimeout ¶
func ReadTimeout ¶
func WriteTimeout ¶
type PriorityMiddleware ¶
type PriorityMiddleware = internal.Middleware
type RequestResponseData ¶
type RequestResponseData = internal.RequestResponseData