Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var StaticRegexp = regexp.MustCompile("/*/*.(js|css|png|jpg|woff|tff|oet)")
Functions ¶
func CacheControl ¶
func CacheControl(filter *regexp.Regexp) gin.HandlerFunc
func ErrorMiddleware ¶
func ErrorMiddleware(logger errLogger) gin.HandlerFunc
ErrorMiddleware 捕获到在http处理时的错误 在 handler 和其他地方如果产生了 error 可直接panic,到这里统一处理,简化 if err != nil 之类的代码 panic("text") => {msg: "text", code: 0, data: {}} panic(gin.H{"code": 0, "msg": "some error"}) => {与传入的数据一致,} code 默认999999,status 默认 400,msg 默认 unknow error panic(errors.New("some error")) => {msg: "some error", code: 999999, data: {}} panic(Struct{...}) => {msg: "unknow", code: 999999, data: {...struct 数据}}
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 RecoveryWithZap ¶
func RecoveryWithZap(logger *zap.Logger, stack bool) gin.HandlerFunc
RecoveryWithZap returns a gin.HandlerFunc (middleware) that recovers from any panics and logs requests using uber-go/zap. All errors are logged using zap.Error(). stack means whether output the stack info. The stack info is easy to find where the error occurs but the stack info is too large.
Types ¶
This section is empty.