入口
api := iris.New()
api.Adapt(gm.NewSession())
session的构造
func NewSession() sessions.Sessions {
db := redis.New(rs.Config{Network: rs.DefaultRedisNetwork,
Addr: config.Instance().Redis.Address,
Password: config.Instance().Redis.Password,
Database: "",
MaxIdle: 0,
MaxActive: 0,
IdleTimeout: rs.DefaultRedisIdleTimeout,
Prefix: "",
MaxAgeSeconds: config.Instance().Redis.MaxAgeSeconds}) // optionally configure the bridge between your redis server
mySessions := sessions.New(sessions.Config{Cookie: configs.GetSessionConfig().Cookie, Expires: configs.GetSessionConfig().Expires})
mySessions.UseDatabase(db)
return mySessions
}
MaxAgeSeconds //指的是session在数据库存的有效期
Expires //指的是session的有效期
回到刚才的api.Adapt(gm.NewSession()),装饰器
func (s *sessions) Adapt(frame *iris.Policies) {
// for newcomers this maybe looks strange:
// Each policy is an adaptor too, so they all can contain an Adapt.
// If they contains an Adapt func then the policy is an adaptor too and this Adapt func is called
// by Iris on .Adapt(...)
policy := iris.SessionsPolicy{
Start: s.Start,
Destroy: s.Destroy,
}
policy.Adapt(frame)
func (s S