setting.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package global
  2. import (
  3. global "project_management/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. // Qiniu qiniu
  47. type Qiniu struct {
  48. AccessKeyID string `json:"accessKeyID"`
  49. Endpoint string `json:"endpoint"`
  50. AccessKeySecret string `json:"accessKeySecret"`
  51. BucketName string `json:"bucketName"`
  52. }
  53. type ICon struct {
  54. IconPath string `json:"iconPath"`
  55. BackgroundImagePc string `json:"BackgroundImagePc"`
  56. BackgroundImageMobile string `json:"BackgroundImageMobile"`
  57. StartupDiagramPc string `json:"StartupDiagramPc"`
  58. StartupDiagramMobile string `json:"StartupDiagramMobile"`
  59. }
  60. var (
  61. DatabaseSetting *DatabaseSettingS
  62. NatsSetting *Nats
  63. JwtSetting *Jwt
  64. ServerSetting *ServerSettingS
  65. SubMailSetting *SubMail
  66. RedisSetting *Redis
  67. SwaggerSetting *Swagger
  68. QiniuSetting *Qiniu
  69. IconSetting *ICon
  70. )
  71. // SetupSetting 读取配置到全局变量
  72. func SetupSetting() error {
  73. s, err := global.NewSetting()
  74. err = s.ReadSection("Database", &DatabaseSetting)
  75. err = s.ReadSection("Nats", &NatsSetting)
  76. err = s.ReadSection("Jwt", &JwtSetting)
  77. err = s.ReadSection("Server", &ServerSetting)
  78. err = s.ReadSection("SubMail", &SubMailSetting)
  79. err = s.ReadSection("Redis", &RedisSetting)
  80. err = s.ReadSection("Swagger", &SwaggerSetting)
  81. err = s.ReadSection("Qiniu", &QiniuSetting)
  82. err = s.ReadSection("ICon", &IconSetting)
  83. if err != nil {
  84. return err
  85. }
  86. return nil
  87. }