Documentation ¶
Index ¶
- Constants
- Variables
- func ClearUserTokenInMemory(ctx context.Context, userId int64) error
- func ClearUserTokenInRedis(ctx context.Context, userId int64) error
- func GenerateTokenToMemory(ctx context.Context, userId int64) (string, error)
- func GenerateTokenToRedis(ctx context.Context, userId int64) (string, error)
- func GetCacheExpireDt() int64
- func GetCacheExpireDtDuration() time.Duration
- func GetCacheMode() string
- func GetIssuer() string
- func GetRedisName() string
- func InitAuthRule()
- func Login(ctx context.Context, userId int64) (string, error)
- func Logout(ctx context.Context, userId int64) (string, error)
- func ReInitAuthRule()
- func RequiredPermission(r *ghttp.Request)
- func RequiredToken(r *ghttp.Request)
- func SetGetGroupCodesFunc(f func(ctx context.Context, userId int64) ([]string, error))
- func SetGetPermissionCodes(f func(ctx context.Context, userId int64) ([]string, error))
- func SetGetPlatformFunc(f func(ctx context.Context) string)
- type CurrentUser
- type DefaultHandlerResponse
- type Rule
- type RuleConfig
- type RulePermission
- type SimpleTokenContent
Constants ¶
View Source
const ( CachePrefixUserToken = "USER_TOKEN" CachePrefixUserPermission = "USER_PERMISSION" CachePrefixUserTokenArray = "USER_TOKEN_ARRAY" )
View Source
const ( CacheModeRedis = "REDIS" CacheModeMemory = "MEMORY" )
View Source
const ( OR = "OR" AND = "AND" EXCLUDE = "EXCLUDE" )
View Source
const CtxUserId = "CtxUserId"
Variables ¶
View Source
var ( IllegalPermissionError = apiError(40000, "非法权限") IllegalTokensError = apiError(40001, "非法token") UrlPrefixError = apiError(40002, "路由前缀错误") PlatformError = apiError(40003, "平台名称错误") )
Functions ¶
func GenerateTokenToMemory ¶
func GenerateTokenToRedis ¶
func GetCacheExpireDt ¶
func GetCacheExpireDt() int64
func GetCacheMode ¶
func GetCacheMode() string
func GetRedisName ¶
func GetRedisName() string
func InitAuthRule ¶
func InitAuthRule()
func ReInitAuthRule ¶
func ReInitAuthRule()
func RequiredPermission ¶ added in v0.0.4
func RequiredToken ¶ added in v0.0.4
func SetGetGroupCodesFunc ¶
func SetGetPermissionCodes ¶
func SetGetPlatformFunc ¶
Types ¶
type CurrentUser ¶
type CurrentUser struct {
UserId int64
}
type DefaultHandlerResponse ¶
type Rule ¶
type Rule struct { sync.RWMutex Path string `json:"path" v:"required" dc:"路由"` Permission []RulePermission `json:"permission" dc:"权限内容"` }
type RuleConfig ¶
type RuleConfig struct { sync.RWMutex RedisName string `json:"redisName" dc:"redis名称"` Issuer string `json:"issuer" v:"required" dc:"Token签发者"` CacheMode string `json:"cacheMode" v:"required|in:redis,memory" d:"no" dc:"token是否使用缓存以及缓存的方式"` ExpireDt int64 `json:"expireDt" v:"required-unless:cacheMode" dc:"缓存有效时间"` Rule []Rule `json:"rule" dc:"权限路由集合"` }
type RulePermission ¶
type RulePermission struct { Group []string `json:"group" dc:"角色限制"` GroupMode string `` /* 145-byte string literal not displayed */ Code []string `json:"code"` CodeMode string `json:"codeMode" v:"required-with:code|in:or,and,exclude,OR,AND,EXCLUDE" d:"or" dc:"权限以OR还是AND的方式校验"` }
func GetRule ¶
func GetRule(path string) []RulePermission
type SimpleTokenContent ¶
type SimpleTokenContent struct { UserId int64 `json:"userId" v:"required" dc:"用户ID"` ExpireDt int64 `json:"expireDt" v:"required" dc:"有效期"` IssuedDt time.Time `json:"issuedDt" v:"required" dc:"签发时间"` Issuer string `json:"issuer" v:"required" dc:"签发者"` }
SimpleTokenContent jwt token原始内容
func NewSimpleTokenContent ¶
func NewSimpleTokenContent(userId int64) *SimpleTokenContent
NewSimpleTokenContent 快速创建token内容
func (*SimpleTokenContent) IsValidate ¶
func (j *SimpleTokenContent) IsValidate() bool
Click to show internal directories.
Click to hide internal directories.