Documentation
¶
Index ¶
- Variables
- func DefaultResponseHandler(ctx *gin.Context, code int, msg string, data interface{})
- func GetConnectionNum() int64
- func GinZap(timeFormat string, utc bool, mod string) gin.HandlerFunc
- func RecoveryWithZap(stack bool) gin.HandlerFunc
- type JWTMiddleware
- type Option
- func WithErrResponseHandler(handler ResponseHandler) Option
- func WithErrorCode(code int) Option
- func WithFactory(factory jwt.JWTFactory) Option
- func WithResponseHandler(handler ResponseHandler) Option
- func WithSuccessCode(code int) Option
- func WithTokenLookup(tokenLookup string) Option
- func WithTokenName(name string) Option
- type ResponseHandler
Constants ¶
This section is empty.
Variables ¶
View Source
var TokenNotFoundErr = errors.New("token not found err")
Functions ¶
func DefaultResponseHandler ¶
func GinZap ¶
func GinZap(timeFormat string, utc bool, mod string) gin.HandlerFunc
GinZap returns a xgin.HandlerFunc (middleware) that logs requests using uber-go/ginzap.
Requests with errors are logged using ginzap.Error(). Requests without errors are logged using ginzap.Info().
It receives:
- A time package format string (e.g. time.RFC3339).
- A boolean stating whether to use UTC time zone or local.
- A string stating whether to log response body
func RecoveryWithZap ¶
func RecoveryWithZap(stack bool) gin.HandlerFunc
RecoveryWithZap returns a ginzap.HandlerFunc (middleware) that recovers from any panics and logs requests using uber-go/ginzap. All errors are logged using ginzap.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 ¶
type JWTMiddleware ¶
type JWTMiddleware struct {
// contains filtered or unexported fields
}
func NewJWTMiddleware ¶
func NewJWTMiddleware(opts ...Option) JWTMiddleware
func (JWTMiddleware) GenerateTokenHandler ¶
func (j JWTMiddleware) GenerateTokenHandler() gin.HandlerFunc
func (JWTMiddleware) GetToken ¶
func (j JWTMiddleware) GetToken(ctx *gin.Context) (token string, err error)
func (JWTMiddleware) MiddleWareImpl ¶
func (j JWTMiddleware) MiddleWareImpl() gin.HandlerFunc
type Option ¶
type Option func(middleware *JWTMiddleware)
func WithErrResponseHandler ¶
func WithErrResponseHandler(handler ResponseHandler) Option
func WithErrorCode ¶
func WithFactory ¶
func WithFactory(factory jwt.JWTFactory) Option
func WithResponseHandler ¶
func WithResponseHandler(handler ResponseHandler) Option
func WithSuccessCode ¶
func WithTokenLookup ¶
func WithTokenName ¶
Click to show internal directories.
Click to hide internal directories.