You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
1.8 KiB

2 years ago
  1. package config
  2. import (
  3. "gitea.baoapi.com/root/stu_uuos/util"
  4. "github.com/micro/go-micro/v2/config"
  5. )
  6. var conf *Config
  7. type Config struct {
  8. Version string
  9. ServiceName string
  10. Address int
  11. SinglePoint bool
  12. Domain string
  13. DB *Database // postgress -> gy_uums
  14. DB2 *Database // postgress -> gy_order
  15. DB3 *Database // postgress -> gy_cloud
  16. Log *Log
  17. LogrusHttp *LogrusHttp
  18. ApiAddr *ApiAddress `yaml:"apiAddr"`
  19. Redis *Redis
  20. Nats *Nats
  21. JWT *Jwt
  22. Minio *Minio
  23. Micro *Micro
  24. Gather *Gather
  25. Gyys *Gyys
  26. Mail *Mail
  27. CompanyWxSync *CompanyWxSync
  28. }
  29. type Gather struct {
  30. Domain string
  31. Userid string
  32. Orgid string
  33. }
  34. type Gyys struct {
  35. Domain string
  36. }
  37. type Nats struct {
  38. Addr string
  39. Subject map[string]string
  40. }
  41. type Jwt struct {
  42. SigningKey string
  43. }
  44. type Micro struct {
  45. Registry Registry
  46. Service Service
  47. }
  48. type Registry struct {
  49. Name string
  50. Addrs string
  51. }
  52. type Service struct {
  53. Cipher string
  54. }
  55. //CompanyWxSync 运营企业微信同步
  56. type CompanyWxSync struct {
  57. Id string //商户id
  58. PartyId string //目标部门id
  59. }
  60. func GetConfig() *Config {
  61. return conf
  62. }
  63. func Init() {
  64. if conf != nil {
  65. return
  66. }
  67. f, err := util.FindFile("conf.yaml")
  68. if err != nil {
  69. panic(err)
  70. }
  71. util.PrintInfo(f)
  72. if err := config.LoadFile(f); err != nil {
  73. panic(err)
  74. }
  75. conf = &Config{}
  76. if err := config.Scan(conf); err != nil {
  77. panic(err)
  78. }
  79. util.PrintJSON(conf)
  80. go watch(f)
  81. }
  82. func watch(f string) {
  83. w, err := config.Watch(f)
  84. if err != nil {
  85. util.PrintErr(err)
  86. return
  87. }
  88. v, err := w.Next()
  89. if err != nil {
  90. util.PrintErr(err)
  91. return
  92. }
  93. if err := v.Scan(conf); err != nil {
  94. util.PrintErr(err)
  95. }
  96. util.PrintInfo("the config file 'conf.yaml' has been changed:")
  97. util.PrintJSON(conf)
  98. }