middlewares

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

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")
)
View Source
var Middlewares = defaultMiddlewares()

Functions

func Context

func Context() gin.HandlerFunc

Context 请求上下文中间件,用于将一些常用的信息放入到gin.Context中

func Cors

func Cors() gin.HandlerFunc

func JWTAuth added in v0.0.4

func JWTAuth(signKey string) gin.HandlerFunc

TODO 弃用,使用了通用中间件,实现验证

func TracingHandler

func TracingHandler(service string) gin.HandlerFunc

Types

type AuthOperator

type AuthOperator struct {
	// contains filtered or unexported fields
}

AuthOperator 认证实体工厂类

func (*AuthOperator) AuthFunc

func (ao *AuthOperator) AuthFunc() gin.HandlerFunc

AuthFunc 返回一个 gin.HandlerFunc 中间件接口函数

func (*AuthOperator) SetStrategy

func (ao *AuthOperator) SetStrategy(s AuthStrategy)

type AuthStrategy

type AuthStrategy interface {
	// AuthFunc 相当于是实现了一个名为 AuthFunc 的中间件
	AuthFunc() gin.HandlerFunc
}

AuthStrategy 认证策略

type CustomClaims added in v0.0.4

type CustomClaims struct {
	ID          uint `json:"userid"`
	NickName    string
	AuthorityId uint
	jwt.StandardClaims
}

type JWT added in v0.0.4

type JWT struct {
	SigningKey []byte
}

func NewJWT added in v0.0.4

func NewJWT(sign string) *JWT

func (*JWT) CreateToken added in v0.0.4

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

创建一个token

func (*JWT) ParseToken added in v0.0.4

func (j *JWT) ParseToken(tokenString string) (*CustomClaims, error)

解析 token

func (*JWT) RefreshToken added in v0.0.4

func (j *JWT) RefreshToken(tokenString string) (string, error)

更新token

Directories

Path Synopsis
Package auth defines authentication strategy like Basic, Bearer.
Package auth defines authentication strategy like Basic, Bearer.

Jump to

Keyboard shortcuts

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