setting.go 1.9 KB

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