Documentation
¶
Index ¶
- Constants
- func MaxAllowed(n int) gin.HandlerFunc
- func RegisterValidation(param string, fun ValidFunc)
- func Sequence(limit int64, onrepeat func(*gin.Context)) gin.HandlerFunc
- func Session(name string, maxLifeTime int64) gin.HandlerFunc
- func Sign(signKey, secret string) gin.HandlerFunc
- type Claims
- type JWT
- type JWTConfigInterface
- type MemSession
- type SessionEngine
- type ValidFunc
Constants ¶
View Source
const GC_TIME = 60 //单位:秒
缓存更新时间
View Source
const (
GIN_KEY_JWT = "gin_key_jwt"
)
type Handler struct { } //发行者
func (this *Handler) Issuer() string {
return "test"
}
//设置密匙
func (this *Handler) Secret() string {
return "abcdefaasdfasdft"
}
//获取token的方式
func (this *Handler) Token(w *Wontext) string {
var token = ""
if w.Request.Header["Authorization"] != nil {
token = w.Request.Header["Authorization"][0]
}
return token
}
//当错误时
func (this *Handler) Error(w *Wontext) {
token, e := w.GenerateToken("hait", "hait", 323)
fmt.Println("jwt 加密结果:", token, e)
w.Succ(100, token)
}
//当超时时 func (this *Handler) Timeout(w *Wontext) {
}
View Source
const (
GIN_KEY_SESSION = "SESSION"
)
Variables ¶
This section is empty.
Functions ¶
func Sequence ¶
func Sequence(limit int64, onrepeat func(*gin.Context)) gin.HandlerFunc
防止请求重复提交中间件 忽略GET请求 limit=限制重复提交的时间,onrepeat=当发生重复请求时执行的回调函数
func Session ¶
func Session(name string, maxLifeTime int64) gin.HandlerFunc
session中间件 name=session名称 maxLifeTime=session过期时间
func Sign ¶
func Sign(signKey, secret string) gin.HandlerFunc
Types ¶
type Claims ¶
type Claims struct {
UserId int64 `json:"userid"`
Username string `json:"username"`
Outtime int64 `json:"outTime"`
Group string `json:"group"`
jwt.StandardClaims
}
jwt数据保存结构
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
jwt处理结构,继承使用
func (*JWT) GenerateToken ¶
生成token username 用户名 id 用户id group 用户组
func (*JWT) Init ¶
func (this *JWT) Init(conf JWTConfigInterface)
type JWTConfigInterface ¶
type JWTConfigInterface interface {
Group() string //分组
Issuer() string //发行人
Secret() string //密匙
Token(*gin.Context) string //口令获取方式
Error(*gin.Context) //当出现错误时
Timeout(*gin.Context) //当超时
Duration() time.Duration //生存时间(单位分)
}
jwt配置接口
type MemSession ¶
session对象
func (*MemSession) Clear ¶
func (this *MemSession) Clear()
func (*MemSession) Del ¶
func (this *MemSession) Del(key string)
func (*MemSession) Get ¶
func (this *MemSession) Get(key string) interface{}
func (*MemSession) Id ¶
func (this *MemSession) Id() string
func (*MemSession) Set ¶
func (this *MemSession) Set(key string, value interface{})
type SessionEngine ¶
type SessionEngine struct {
// contains filtered or unexported fields
}
session engine
Click to show internal directories.
Click to hide internal directories.