middler

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextPathKey   = "path"
	ContextMethodKey = "method"
)
View Source
const AdminRole = 1

Variables

View Source
var (
	ErrTokenInvalid = perrors.ErrorUnauthorized("请先登录")
	ErrLogout       = perrors.ErrorUnauthorized("令牌已失效, 请重新登录")
)

Functions

func Context

func Context() http.FilterFunc

func Cors

func Cors() func(http.Handler) http.Handler

func Expire

func Expire(ctx context.Context, rdsClient cache.GlobalCache, authClaims *AuthClaims) error

Expire 把token过期掉

func GetMethod

func GetMethod(ctx context.Context) string

func GetPath

func GetPath(ctx context.Context) string

func GetRoleId

func GetRoleId(ctx context.Context) uint32

GetRoleId get role id

func GetUserId

func GetUserId(ctx context.Context) uint32

GetUserId get user id

func IpMetric

func IpMetric(counter *prometheus.CounterVec) middleware.Middleware

func IsAdminRole

func IsAdminRole(ctx context.Context) bool

IsAdminRole 是否是管理员

func IsLogout

func IsLogout(ctx context.Context, rdsClient cache.GlobalCache, authClaims *AuthClaims) error

IsLogout 判断token是否被logout

func IssueToken

func IssueToken(id, role uint32) (string, error)

IssueToken issue token

func IssueTokenWithDuration

func IssueTokenWithDuration(id uint32, role uint32, duration time.Duration) (string, error)

IssueTokenWithDuration issue token with duration

func JwtServer

func JwtServer() middleware.Middleware

JwtServer jwt server

func LocalHttpRequestFilter

func LocalHttpRequestFilter() http.FilterFunc

func Logging

func Logging(logger log.Logger) middleware.Middleware

Logging is an server logging middleware.

func MustLogin

func MustLogin(cache ...cache.GlobalCache) middleware.Middleware

MustLogin 必须登录

func NewWhiteListMatcher

func NewWhiteListMatcher(list []string) selector.MatchFunc

func SetExpire added in v0.0.20

func SetExpire(d time.Duration)

SetExpire 设置过期时间

func SetIssuer added in v0.0.20

func SetIssuer(i string)

SetIssuer 设置issuer

func SetSecret

func SetSecret(s string)

SetSecret set secret

Types

type AuthClaims

type AuthClaims struct {
	ID   uint32 `json:"id"`
	Role uint32 `json:"role"`
	*jwtv4.RegisteredClaims
}

AuthClaims jwt claims

func GetAuthClaims

func GetAuthClaims(ctx context.Context) (*AuthClaims, bool)

GetAuthClaims get auth claims

func (*AuthClaims) Bytes

func (l *AuthClaims) Bytes() []byte

func (*AuthClaims) MD5

func (l *AuthClaims) MD5() string

func (*AuthClaims) String

func (l *AuthClaims) String() string

type CheckUserRoleExistFun

type CheckUserRoleExistFun func(ctx context.Context, userID, roleID uint32) error

type GetApiIDByPathAndMethodFun

type GetApiIDByPathAndMethodFun func(ctx context.Context, path, method string) (uint64, error)

Jump to

Keyboard shortcuts

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