Documentation ¶
Index ¶
Constants ¶
View Source
const ( //TokenKey Redis 存储的hashMap,保存用户令牌 TokenKey = "/h/token" HeaderAuth = "Authorization" BearerVal = "Bearer " )
常量定义
Variables ¶
View Source
var ( ErrPlace = errors.New("存在异地操作行为: 令牌失效") ErrInvalid = errors.New("非法的令牌: 令牌已失效") )
错误定义
View Source
var DefOption = &Option{ Debug: true, Secret: []byte("AYtY0RD5hvN2T0McxjNWfH1MM7PExE0w"), ExpirePeriod: time.Hour * 10, SingleLogin: true, VerifyIP: false, }
DefOption 默认配置
View Source
var GAuth = newAuth()
GAuth 对外暴露,全局唯一对象
Functions ¶
func AESDecrypt ¶
AESDecrypt decrypts a piece of data. The cipherkey argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
func AESEncrypt ¶
AESEncrypt encrypts a piece of data. The cipherkey argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
Types ¶
type Claims ¶
type Claims struct { jwt.StandardClaims ClientIP string `json:"ip,omitempty"` }
Claims jwt 载荷 请求体结构
type IAuth ¶
type IAuth interface { SetOut(out io.Writer) SetStore(store IStore) SetOption(opt *Option) GenerateToken(req IRequester, fn BindClaimsFunc) (tk string, err error) Verify(req IRequester) (err error) Encrypt(str string) string Decrypt(str string) (rs string, err error) }
IAuth 身份验证接口
type IRequester ¶
type IRequester interface { ClientIP() string GetHeader(key string) string Header(key, value string) Set(string, interface{}) }
IRequester jwt验校时的入参对象接口
Click to show internal directories.
Click to hide internal directories.