Documentation ¶
Overview ¶
Package middleware gzip to enable GZIP support. Ref: https://github.com/gin-contrib/gzip
Package middleware pprof serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool. Ref: https://github.com/gin-contrib/pprof
Package middleware ginzap provides log handling using zap package. Code structure based on ginrus package. Ref: https://github.com/gin-contrib/zap
Index ¶
- Constants
- func Cors() gin.HandlerFunc
- func CorsWithOption(option CorsOption) gin.HandlerFunc
- func Ginzap(logger *zap.Logger, timeFormat string, utc bool) gin.HandlerFunc
- func GinzapWithConfig(logger *zap.Logger, conf *ZapConfig) gin.HandlerFunc
- func Gzip(level int, options ...gzips.Option) gin.HandlerFunc
- func HeaderAuth(k string, v string, json bool) gin.HandlerFunc
- func JwtAuth(headerKey string, secret string) gin.HandlerFunc
- func NoCache(c *gin.Context)
- func PprofRegister(r *gin.Engine, prefixOptions ...string)
- func PprofRouteRegister(rg *gin.RouterGroup, prefixOptions ...string)
- func RestRecovery(stack bool) gin.RecoveryFunc
- type CorsOption
- type ZapConfig
Constants ¶
const ( CorsDefaultAllowOrigin = "*" CorsDefaultAllowMethods = "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS" CorsDefaultAllowHeaders = "Origin, Content-Type, X-CSRF-Token, Authorization, Jwt-Authorization, X-Requested-With, Accept, X-Cookie" CorsDefaultExposeHeaders = "Content-Length, Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma" CorsDefaultAllowCredentials = "true" CorsDefaultMaxAge = "86400" )
const (
// PprofDefaultPrefix url prefix of pprof
PprofDefaultPrefix = "/debug/pprof"
)
Variables ¶
This section is empty.
Functions ¶
func Cors ¶
func Cors() gin.HandlerFunc
Cors is a middleware function that appends headers to allow CORS with default config
func CorsWithOption ¶ added in v0.24.0
func CorsWithOption(option CorsOption) gin.HandlerFunc
CorsWithOption is a middleware function that appends headers to allow CORS with option
func Ginzap ¶
Ginzap returns a gin.HandlerFunc (middleware) that logs requests using uber-go/zap.
Requests with errors are logged using zap.Error(). Requests without errors are logged using zap.Info().
It receives:
- A time package format string (e.g. time.RFC3339).
- A boolean stating whether to use UTC time zone or local.
func GinzapWithConfig ¶
func GinzapWithConfig(logger *zap.Logger, conf *ZapConfig) gin.HandlerFunc
GinzapWithConfig returns a gin.HandlerFunc using configs
func HeaderAuth ¶
func HeaderAuth(k string, v string, json bool) gin.HandlerFunc
HeaderAuth is a middleware function that validates the request header. Return http forbidden code or rest json
func JwtAuth ¶ added in v0.19.0
func JwtAuth(headerKey string, secret string) gin.HandlerFunc
JwtAuth jwt 中间件
func PprofRegister ¶ added in v0.3.0
PprofRegister the standard HandlerFuncs from the net/http/pprof package with the provided gin.Engine. prefixOptions is a optional. If not prefixOptions, the default path prefix is used, otherwise first prefixOptions will be path prefix.
func PprofRouteRegister ¶ added in v0.3.0
func PprofRouteRegister(rg *gin.RouterGroup, prefixOptions ...string)
PprofRouteRegister the standard HandlerFuncs from the net/http/pprof package with the provided gin.GrouterGroup. prefixOptions is a optional. If not prefixOptions, the default path prefix is used, otherwise first prefixOptions will be path prefix.
func RestRecovery ¶ added in v0.16.0
func RestRecovery(stack bool) gin.RecoveryFunc
RestRecovery For gin.CustomRecovery