middlewares

package
v0.0.0-...-a23f37e Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UsernameKey = "username"
	KeyUserID   = "userid"
	UserIP      = "ip"
)

Variables

View Source
var (
	TokenExpired     = errors.New("token is expired")
	TokenNotValidYet = errors.New("token not active yet")
	TokenMalformed   = errors.New("that's not even a token")
	TokenInvalid     = errors.New("couldn't handle this token")
)

Functions

func Context

func Context() gin.HandlerFunc

Context 为每个请求添加上下文, 类型 django 中间件

func CorsHandler

func CorsHandler() gin.HandlerFunc

CorsHandler 解决跨域访问问题

func LimitHandler

func LimitHandler() gin.HandlerFunc

LimitHandler 创建 熔断限流功能 拦截器

func RecoveryHandler

func RecoveryHandler() gin.HandlerFunc

RecoveryHandler 将 在 错误 中恢复 并返回 500 http 状态码

func TracingHandler

func TracingHandler(service string) gin.HandlerFunc

Types

type JWT

type JWT struct {
	SigningAlgorithm string // jwt签名算法
	HsSigningKey     []byte // jwt密钥
	EsPrivKey        *ecdsa.PrivateKey
	RsPrivKey        *rsa.PrivateKey
}

func NewJWT

func NewJWT(opts ...JwtOption) *JWT

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims any) (string, error)

CreateToken 创建一个token

func (*JWT) ParseToken

func (j *JWT) ParseToken(tokenString string) (*jwt.MapClaims, error)

ParseToken 解析 token

func (*JWT) RefreshToken

func (j *JWT) RefreshToken(tokenString string, method jwt.SigningMethod) (string, error)

RefreshToken 更新token

type JwtOption

type JwtOption func(j *JWT)

func WithEsAsymmetricEncrypt

func WithEsAsymmetricEncrypt(alg string, privkey *ecdsa.PrivateKey) JwtOption

func WithHsSymmetricEncrypt

func WithHsSymmetricEncrypt(alg string, key []byte) JwtOption

func WithRsAsymmetricEncrypt

func WithRsAsymmetricEncrypt(alg string, privkey *rsa.PrivateKey) JwtOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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