Smail/server/session/init.go
木木的木头 f4689d073c v2.2.0
2023-09-08 02:11:00 +08:00

26 lines
606 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package session
import (
"github.com/alexedwards/scs/mysqlstore"
"github.com/alexedwards/scs/sqlite3store"
"github.com/alexedwards/scs/v2"
"pmail/config"
"pmail/db"
"time"
)
var Instance *scs.SessionManager
func Init() {
Instance = scs.New()
Instance.Lifetime = 7 * 24 * time.Hour
// 使用db存储session数据,目前为了架构简单,
// 暂不引入redis存储,如果日后性能存在瓶颈,可以将session迁移到redis
if config.Instance.DbType == "mysql" {
Instance.Store = mysqlstore.New(db.Instance.DB)
} else {
Instance.Store = sqlite3store.New(db.Instance.DB)
}
}