init.go 859 B

123456789101112131415161718192021222324252627282930313233
  1. package session
  2. import (
  3. "github.com/alexedwards/scs/mysqlstore"
  4. "github.com/alexedwards/scs/postgresstore"
  5. "github.com/alexedwards/scs/sqlite3store"
  6. "github.com/alexedwards/scs/v2"
  7. "pmail/config"
  8. "pmail/db"
  9. "time"
  10. )
  11. var Instance *scs.SessionManager
  12. func Init() {
  13. Instance = scs.New()
  14. Instance.Lifetime = 7 * 24 * time.Hour
  15. // 使用db存储session数据,目前为了架构简单,
  16. // 暂不引入redis存储,如果日后性能存在瓶颈,可以将session迁移到redis
  17. switch config.Instance.DbType {
  18. case config.DBTypeMySQL:
  19. Instance.Store = mysqlstore.New(db.Instance.DB().DB)
  20. case config.DBTypeSQLite:
  21. Instance.Store = sqlite3store.New(db.Instance.DB().DB)
  22. case config.DBTypePostgres:
  23. Instance.Store = postgresstore.New(db.Instance.DB().DB)
  24. default:
  25. panic("Unsupported database type: " + config.Instance.DbType)
  26. }
  27. }