Documentation ¶
Index ¶
- Constants
- Variables
- func Context() http.FilterFunc
- func Cors() func(http.Handler) http.Handler
- func Expire(ctx context.Context, rdsClient cache.GlobalCache, authClaims *AuthClaims) error
- func GetMethod(ctx context.Context) string
- func GetPath(ctx context.Context) string
- func GetRoleId(ctx context.Context) uint32
- func GetUserId(ctx context.Context) uint32
- func IpMetric(counter *prometheus.CounterVec) middleware.Middleware
- func IsAdminRole(ctx context.Context) bool
- func IsLogout(ctx context.Context, rdsClient cache.GlobalCache, authClaims *AuthClaims) error
- func IssueToken(id, role uint32) (string, error)
- func IssueTokenWithDuration(id uint32, role uint32, duration time.Duration) (string, error)
- func JwtServer() middleware.Middleware
- func LocalHttpRequestFilter() http.FilterFunc
- func Logging(logger log.Logger) middleware.Middleware
- func MustLogin(cache ...cache.GlobalCache) middleware.Middleware
- func NewWhiteListMatcher(list []string) selector.MatchFunc
- func RbacServer(checkFun CheckUserRoleExistFun, getApiFun GetApiIDByPathAndMethodFun) middleware.Middleware
- func SetSecret(s string)
- type AuthClaims
- type CheckUserRoleExistFun
- type GetApiIDByPathAndMethodFun
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 Expire ¶
func Expire(ctx context.Context, rdsClient cache.GlobalCache, authClaims *AuthClaims) error
Expire 把token过期掉
func IpMetric ¶
func IpMetric(counter *prometheus.CounterVec) middleware.Middleware
func IsLogout ¶
func IsLogout(ctx context.Context, rdsClient cache.GlobalCache, authClaims *AuthClaims) error
IsLogout 判断token是否被logout
func IssueTokenWithDuration ¶
IssueTokenWithDuration issue token with duration
func LocalHttpRequestFilter ¶
func LocalHttpRequestFilter() http.FilterFunc
func Logging ¶
func Logging(logger log.Logger) middleware.Middleware
Logging is an server logging middleware.
func NewWhiteListMatcher ¶
func RbacServer ¶
func RbacServer(checkFun CheckUserRoleExistFun, getApiFun GetApiIDByPathAndMethodFun) middleware.Middleware
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 ¶
Click to show internal directories.
Click to hide internal directories.