Versions in this module Expand all Collapse all v1 v1.0.0 Sep 7, 2022 Changes in this version + const CacheModeCache + const CacheModeRedis + const DefaultAuthFailMsg + const DefaultCacheKey + const DefaultEncryptKey + const DefaultTimeout + const DefaultTokenDelimiter + const ERROR + const ErrorsParseTokenFail + const ErrorsTokenInvalid + const ErrorsTokenMalFormed + const ErrorsTokenNotActiveYet + const FAIL + const FailedAuthCode + const JwtTokenExpired + const JwtTokenFormatErrCode + const JwtTokenInvalid + const JwtTokenOK + const MiddlewareTypeBind + const MiddlewareTypeGlobal + const MiddlewareTypeGroup + const SUCCESS + const TypeConfig + const TypeDict + const UNAUTHORIZED + type AuthFailed struct + Code int + Message string + type CustomClaims struct + Data interface{} + type GToken struct + AuthAfterFunc func(r *ghttp.Request, respData Resp) + AuthBeforeFunc func(r *ghttp.Request) bool + AuthExcludePaths g.SliceStr + AuthFailMsg string + AuthPaths g.SliceStr + CacheKey string + CacheMode int8 + EncryptKey []byte + GlobalMiddleware bool + LoginAfterFunc func(r *ghttp.Request, respData Resp) + LoginBeforeFunc func(r *ghttp.Request) (string, interface{}) + LoginPath string + LogoutAfterFunc func(r *ghttp.Request, respData Resp) + LogoutBeforeFunc func(r *ghttp.Request) bool + LogoutPath string + MaxRefresh int64 + MiddlewareType uint + MultiLogin bool + ServerName string + Timeout int64 + TokenDelimiter string + func NewGToken(opts ...OptionFunc) *GToken + func (m *GToken) AuthMiddleware(group *ghttp.RouterGroup) bool + func (m *GToken) AuthPath(urlPath string) bool + func (m *GToken) DecryptToken(token string) Resp + func (m *GToken) DecryptUtilToken(ctx context.Context, token string) (DecryptStr, uuid string, err error) + func (m *GToken) EncryptToken(userKey string, uuid string) Resp + func (m *GToken) EncryptUtilToken(ctx context.Context, key string, randStr ...string) (encryptStr, uuid string, err error) + func (m *GToken) GenerateToken(ctx context.Context, key string, data interface{}) (keys string, err error) + func (m *GToken) GetRequestToken(r *ghttp.Request) (token string) + func (m *GToken) GetToken(r *ghttp.Request) (tData *tokenData, err error) + func (m *GToken) GetTokenData(r *ghttp.Request) Resp + func (m *GToken) GetUtilToken(r *ghttp.Request) (tData *tokenData, err error) + func (m *GToken) InitConfig() bool + func (m *GToken) IsLogin(r *ghttp.Request) (b bool, failed *AuthFailed) + func (m *GToken) IsUtilEffective(ctx context.Context, token string) bool + func (m *GToken) IsUtilLogin(r *ghttp.Request) (b bool, failed *AuthFailed) + func (m *GToken) IsUtilNotExpired(token string) (*CustomClaims, int) + func (m *GToken) IsUtilRefresh(token string) bool + func (m *GToken) Login(r *ghttp.Request) + func (m *GToken) Logout(r *ghttp.Request) + func (m *GToken) Middleware(group *ghttp.RouterGroup) error + func (m *GToken) ParseToken(r *ghttp.Request) (*CustomClaims, error) + func (m *GToken) ParseUtilToken(r *ghttp.Request) (*CustomClaims, error) + func (m *GToken) RefreshUtilToken(oldToken string) (newToken string, err error) + func (m *GToken) RemoveGeneralToken(token string) Resp + func (m *GToken) RemoveToken(ctx context.Context, token string) (err error) + func (m *GToken) Start() error + func (m *GToken) Stop() error + func (m *GToken) String() string + type JwtSign struct + SigningKey []byte + func CreateMyJWT(JwtTokenSignKey string) *JwtSign + func (j *JwtSign) CreateToken(claims CustomClaims) (string, error) + func (j *JwtSign) ParseToken(tokenString string) (*CustomClaims, error) + func (j *JwtSign) RefreshToken(tokenString string, extraAddSeconds int64) (string, error) + type OptionFunc func(*GToken) + func WithCacheKey(value string) OptionFunc + func WithEncryptKey(value []byte) OptionFunc + func WithExcludePaths(value g.SliceStr) OptionFunc + func WithGCache() OptionFunc + func WithGRedis(redis ...*gredis.Redis) OptionFunc + func WithGRedisConfig(redisConfig ...*gredis.Config) OptionFunc + func WithMaxRefresh(value int64) OptionFunc + func WithMultiLogin(b bool) OptionFunc + func WithServerName(value string) OptionFunc + func WithTimeout(value int64) OptionFunc + func WithTimeoutAndMaxRefresh(timeout, maxRefresh int64) OptionFunc + func WithUserJwt(key string) OptionFunc + type Resp struct + Code int + Data interface{} + Msg string + func Error(msg string) Resp + func ErrorData(msg string, data interface{}) Resp + func Fail(msg string) Resp + func FailData(msg string, data interface{}) Resp + func Succ(data interface{}) Resp + func Unauthorized(msg string, data interface{}) Resp + func (resp Resp) DataInt() int + func (resp Resp) DataString() string + func (resp Resp) Get(key string) interface{} + func (resp Resp) GetInt(key string) int + func (resp Resp) GetString(key string) string + func (resp Resp) Json() string + func (resp Resp) Success() bool