middleware

package
v0.0.0-...-221f2c5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TokenNotFoundErr = errors.New("token not found err")

Functions

func DefaultResponseHandler

func DefaultResponseHandler(ctx *gin.Context, code int, msg string, data interface{})

func GetConnectionNum

func GetConnectionNum() int64

GetConnectionNum http connectionNum

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:

  1. A time package format string (e.g. time.RFC3339).
  2. A boolean stating whether to use UTC time zone or local.
  3. 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 WithErrorCode(code int) Option

func WithFactory

func WithFactory(factory jwt.JWTFactory) Option

func WithResponseHandler

func WithResponseHandler(handler ResponseHandler) Option

func WithSuccessCode

func WithSuccessCode(code int) Option

func WithTokenLookup

func WithTokenLookup(tokenLookup string) Option

func WithTokenName

func WithTokenName(name string) Option

type ResponseHandler

type ResponseHandler func(ctx *gin.Context, code int, msg string, data interface{})

Jump to

Keyboard shortcuts

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