Singleton.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package jwtx
  2. import (
  3. "crypto/ecdsa"
  4. "gorm.io/gorm"
  5. )
  6. // 单例
  7. var Singleton *SingletonT
  8. // SingletonT ..
  9. type SingletonT struct {
  10. DB map[string]*gorm.DB
  11. Config map[string]GroupConfig
  12. PrivateKey map[string]*ecdsa.PrivateKey
  13. }
  14. // 分组配置
  15. type GroupConfig struct {
  16. // consult[https://gorm.io/docs/connecting_to_the_database.html]"
  17. MysqlDSN string `yaml:"MysqlDSN"`
  18. // 是否开启 IP一致性校验,当前 IP 必须与登录时 IP 一致
  19. CheckIP bool `yaml:"CheckIP"`
  20. // 是否开启 单端登录
  21. SingleEnd bool `yaml:"SingleEnd"`
  22. // 刷新时间间隔(秒)
  23. //
  24. // 超过该时间即可触发 token 刷新、旧 token 进入容错,间隔越小安全性越高
  25. RefreshInterval int64 `yaml:"RefreshInterval"`
  26. // 并发容错时间(秒)
  27. FaultTolerance int64 `yaml:"FaultTolerance"`
  28. // 是否开启 自动续期
  29. //
  30. // 假设:单次登录有效期(7天)
  31. // true 只要 7天 内有操作触发刷新,登录状态就一直延续
  32. // false 不论 7天 内是否操作,7天 后必定要求重新登录
  33. AutomaticRenewal bool `yaml:"AutomaticRenewal"`
  34. // 单次登录有效期(小时)
  35. AccessExpireByHour int64 `yaml:"AccessExpireByHour"`
  36. }