middleware

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessToken            = "AccessToken"
	PanicPassCallbackIsNil = "PassCallback is nil"
	PanicErrCallbackIsNil  = "ErrCallback is nil"
)

Variables

View Source
var ErrIdentityType = errors.New("'identity' must be a struct or a pointer to a struct")

ErrIdentityType is the error for identity type

View Source
var ErrTokenEmpty = errors.New("token is empty")

ErrTokenEmpty is the error for token empty

View Source
var ErrTokenInvalid = errors.New("token is invalid")

ErrTokenInvalid is the error for token invalid

Functions

func AesAuth

func AesAuth[T any](conf *AesAuthConf[T]) gin.HandlerFunc

AesAuth is a middleware for aes auth It will check the token in header

func Cross

func Cross() gin.HandlerFunc

Cross is a middleware to handle cross domain request.

func GiveGatePass

func GiveGatePass[T any](identity T, conf *AesAuthConf[T]) gin.HandlerFunc

GiveGatePass is the pass callback for give gate

func Logger added in v1.1.4

func Logger(logger alog.Logger) gin.HandlerFunc

func Recover added in v1.1.4

func Recover(logger alog.Logger) gin.HandlerFunc

Recover is a middleware that recovers from any panics and writes a 500 if there was one.

Types

type AesAuthConf

type AesAuthConf[T any] struct {
	HeaderKey    string
	PassCallback PassCallback[T]
	ErrCallback  ErrCallback
	AesCipher    *cipher.AesCipher
}

AesAuthConf is the config for AesAuth

func NewAesAuthConf

func NewAesAuthConf[T any](options ...AesAuthConfOption[T]) *AesAuthConf[T]

NewAesAuthConf returns a new AesAuthConf

type AesAuthConfOption added in v1.1.0

type AesAuthConfOption[T any] func(conf *AesAuthConf[T])

func WithAesCipher added in v1.1.0

func WithAesCipher[T any](aesCipher *cipher.AesCipher) AesAuthConfOption[T]

WithAesCipher sets the aes cipher

func WithErrCallback added in v1.1.0

func WithErrCallback[T any](errCallback ErrCallback) AesAuthConfOption[T]

WithErrCallback sets the error callback

func WithHeaderKey added in v1.1.0

func WithHeaderKey[T any](headKey string) AesAuthConfOption[T]

WithHeaderKey sets the header key

func WithPassCallback added in v1.1.0

func WithPassCallback[T any](passCallback PassCallback[T]) AesAuthConfOption[T]

WithPassCallback sets the pass callback

type ErrCallback

type ErrCallback func(ctx *gin.Context, err error)

ErrCallback is the callback for error args are: ctx, err

is the error

type PassCallback

type PassCallback[T any] func(ctx *gin.Context, identity T, token, original string) bool

PassCallback is the callback for pass args are: ctx, identity, token, marshal identity is the identity of the user token is the token for the user original is the original data

Jump to

Keyboard shortcuts

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