setting.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package global
  2. import (
  3. global "lot_interlligentControl/configs"
  4. "time"
  5. )
  6. // DatabaseSettingS 数据库配置
  7. type DatabaseSettingS struct {
  8. Dialect string `json:"dialect"`
  9. Host string `json:"host"`
  10. Port string `json:"port"`
  11. UserName string `json:"userName"`
  12. Password string `json:"password"`
  13. Db string `json:"db"`
  14. OtherParams string `json:"otherParams"`
  15. MaxIdleConn int `json:"max_idle_conn"`
  16. MaxOpenConn int `json:"max_open_conn"`
  17. ConnMaxLifetime string `json:"conn_max_lifetime"`
  18. }
  19. // Nats 配置
  20. type Nats struct {
  21. NatsServerUrl string `json:"NatsServer_Url"`
  22. }
  23. // Jwt 配置
  24. type Jwt struct {
  25. Secret string `json:"secret"`
  26. RefreshExpire time.Time `json:"refresh_expire"`
  27. Issuer string `json:"issuer"`
  28. }
  29. // ServerSettingS 服务器配置
  30. type ServerSettingS struct {
  31. Mode string `json:"mode"`
  32. Port string `json:"port"`
  33. InsecureServingInfo string `json:"insecure_serving_info"`
  34. }
  35. type SubMail struct {
  36. Appid string `json:"appid"`
  37. Signature string `json:"signature"`
  38. }
  39. type Redis struct {
  40. Addr string `json:"addr"`
  41. Password string `json:"password"`
  42. DB int `json:"db"`
  43. }
  44. var (
  45. DatabaseSetting *DatabaseSettingS
  46. NatsSetting *Nats
  47. JwtSetting *Jwt
  48. ServerSetting *ServerSettingS
  49. SubMailSetting *SubMail
  50. RedisSetting *Redis
  51. )
  52. // SetupSetting 读取配置到全局变量
  53. func SetupSetting() error {
  54. s, err := global.NewSetting()
  55. err = s.ReadSection("Database", &DatabaseSetting)
  56. err = s.ReadSection("Nats", &NatsSetting)
  57. err = s.ReadSection("Jwt", &JwtSetting)
  58. err = s.ReadSection("Server", &ServerSetting)
  59. err = s.ReadSection("SubMail", &SubMailSetting)
  60. err = s.ReadSection("Redis", &RedisSetting)
  61. if err != nil {
  62. return err
  63. }
  64. return nil
  65. }