config_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package apollo
  2. import (
  3. "fmt"
  4. "git.bvbej.com/bvbej/base-golang/pkg/time_parse"
  5. "sync"
  6. "testing"
  7. "time"
  8. )
  9. var config = new(Config)
  10. type Config struct {
  11. Server struct {
  12. ListenAddr string `yaml:"listenAddr"`
  13. AppAddr string `yaml:"appAddr"`
  14. AuthAddr string `yaml:"authAddr"`
  15. RtmpBaseAddr string `yaml:"rtmpBaseAddr"`
  16. ProductID string `yaml:"productID"`
  17. } `yaml:"server"`
  18. EncryptKeys struct {
  19. AesKey string `yaml:"aesKey"`
  20. AesIv string `yaml:"aesIv"`
  21. } `yaml:"encryptKeys"`
  22. MySQL struct {
  23. Read struct {
  24. Addr string `yaml:"addr"`
  25. User string `yaml:"user"`
  26. Pass string `yaml:"pass"`
  27. Name string `yaml:"name"`
  28. } `yaml:"read"`
  29. Write struct {
  30. Addr string `yaml:"addr"`
  31. User string `yaml:"user"`
  32. Pass string `yaml:"pass"`
  33. Name string `yaml:"name"`
  34. } `yaml:"write"`
  35. Base struct {
  36. MaxOpenConn int `yaml:"maxOpenConn"` //最大连接数
  37. MaxIdleConn int `yaml:"maxIdleConn"` //最大空闲连接数
  38. ConnMaxLifeTime time.Duration `yaml:"connMaxLifeTime"` //最大连接超时(分钟)
  39. } `yaml:"base"`
  40. } `yaml:"mysql"`
  41. Redis struct {
  42. Addr string `yaml:"addr"`
  43. Pass string `yaml:"pass"`
  44. Db int `yaml:"db"`
  45. MaxRetries int `yaml:"maxRetries"` // 最大重试次数
  46. PoolSize int `yaml:"poolSize"` // Redis连接池大小
  47. MinIdleConn int `yaml:"minIdleConn"` // 最小空闲连接数
  48. } `yaml:"redis"`
  49. URLToken struct {
  50. Secret string `yaml:"secret"`
  51. ExpireDuration time.Duration `yaml:"expireDuration"` //毫秒
  52. } `yaml:"urlToken"`
  53. HashIds struct {
  54. Secret string `yaml:"secret"`
  55. Length int `yaml:"length"`
  56. } `yaml:"hashids"`
  57. DingTalkAlert struct {
  58. Service struct {
  59. AccessToken string `yaml:"accessToken"`
  60. Secret string `yaml:"secret"`
  61. } `yaml:"service"`
  62. Alarm struct {
  63. AccessToken string `yaml:"accessToken"`
  64. Secret string `yaml:"secret"`
  65. } `yaml:"alarm"`
  66. } `yaml:"dingTalkAlert"`
  67. IPProxy struct {
  68. Addr string `yaml:"addr"`
  69. BasicAuth struct {
  70. Username string `yaml:"username"`
  71. Password string `yaml:"password"`
  72. } `yaml:"basicAuth"`
  73. CheckAddr string `yaml:"checkAddr"`
  74. CheckAuth struct {
  75. Username string `yaml:"username"`
  76. Password string `yaml:"password"`
  77. } `yaml:"checkAuth"`
  78. } `yaml:"ipProxy"`
  79. APP struct {
  80. IOS struct {
  81. Version string `yaml:"version"`
  82. IsForce bool `yaml:"isForce"`
  83. DownloadUrl string `yaml:"downloadUrl"`
  84. Log string `yaml:"log"`
  85. } `yaml:"ios"`
  86. Android struct {
  87. Version string `yaml:"version"`
  88. IsForce bool `yaml:"isForce"`
  89. DownloadUrl string `yaml:"downloadUrl"`
  90. Log string `yaml:"log"`
  91. Size uint64 `yaml:"size"`
  92. } `yaml:"android"`
  93. } `yaml:"app"`
  94. Mail struct {
  95. Host string `yaml:"host"`
  96. Port int `yaml:"port"`
  97. User string `yaml:"user"`
  98. Pass string `yaml:"pass"`
  99. To string `yaml:"to"`
  100. } `yaml:"mail"`
  101. Alipay struct {
  102. NotifyURL string `yaml:"notifyURL"`
  103. QuitURL string `yaml:"quitURL"`
  104. returnURL string `yaml:"returnURL"`
  105. Debug bool `yaml:"debug"`
  106. } `yaml:"alipay"`
  107. QiNiu struct {
  108. MoguCloud struct {
  109. AccessKey string `yaml:"accessKey"`
  110. SecretKey string `yaml:"secretKey"`
  111. SecurityKey string `yaml:"securityKey"`
  112. Bucket string `yaml:"bucket"`
  113. Domain string `yaml:"domain"`
  114. } `yaml:"moguCloud"`
  115. } `yaml:"qiNiu"`
  116. }
  117. func TestGetApolloConfig(t *testing.T) {
  118. var wait sync.WaitGroup
  119. wait.Add(1)
  120. GetApolloConfig("**", "**", config)
  121. go func() {
  122. for range time.NewTicker(time.Second).C {
  123. fmt.Println(config.APP.IOS.Log, time.Now().Format(time_parse.CSTLayout))
  124. }
  125. }()
  126. wait.Wait()
  127. }