package apollo import ( "fmt" "git.bvbej.com/bvbej/base-golang/pkg/time_parse" "sync" "testing" "time" ) var config = new(Config) type Config struct { Server struct { ListenAddr string `yaml:"listenAddr"` AppAddr string `yaml:"appAddr"` AuthAddr string `yaml:"authAddr"` RtmpBaseAddr string `yaml:"rtmpBaseAddr"` ProductID string `yaml:"productID"` } `yaml:"server"` EncryptKeys struct { AesKey string `yaml:"aesKey"` AesIv string `yaml:"aesIv"` } `yaml:"encryptKeys"` MySQL struct { Read struct { Addr string `yaml:"addr"` User string `yaml:"user"` Pass string `yaml:"pass"` Name string `yaml:"name"` } `yaml:"read"` Write struct { Addr string `yaml:"addr"` User string `yaml:"user"` Pass string `yaml:"pass"` Name string `yaml:"name"` } `yaml:"write"` Base struct { MaxOpenConn int `yaml:"maxOpenConn"` //最大连接数 MaxIdleConn int `yaml:"maxIdleConn"` //最大空闲连接数 ConnMaxLifeTime time.Duration `yaml:"connMaxLifeTime"` //最大连接超时(分钟) } `yaml:"base"` } `yaml:"mysql"` Redis struct { Addr string `yaml:"addr"` Pass string `yaml:"pass"` Db int `yaml:"db"` MaxRetries int `yaml:"maxRetries"` // 最大重试次数 PoolSize int `yaml:"poolSize"` // Redis连接池大小 MinIdleConn int `yaml:"minIdleConn"` // 最小空闲连接数 } `yaml:"redis"` URLToken struct { Secret string `yaml:"secret"` ExpireDuration time.Duration `yaml:"expireDuration"` //毫秒 } `yaml:"urlToken"` HashIds struct { Secret string `yaml:"secret"` Length int `yaml:"length"` } `yaml:"hashids"` DingTalkAlert struct { Service struct { AccessToken string `yaml:"accessToken"` Secret string `yaml:"secret"` } `yaml:"service"` Alarm struct { AccessToken string `yaml:"accessToken"` Secret string `yaml:"secret"` } `yaml:"alarm"` } `yaml:"dingTalkAlert"` IPProxy struct { Addr string `yaml:"addr"` BasicAuth struct { Username string `yaml:"username"` Password string `yaml:"password"` } `yaml:"basicAuth"` CheckAddr string `yaml:"checkAddr"` CheckAuth struct { Username string `yaml:"username"` Password string `yaml:"password"` } `yaml:"checkAuth"` } `yaml:"ipProxy"` APP struct { IOS struct { Version string `yaml:"version"` IsForce bool `yaml:"isForce"` DownloadUrl string `yaml:"downloadUrl"` Log string `yaml:"log"` } `yaml:"ios"` Android struct { Version string `yaml:"version"` IsForce bool `yaml:"isForce"` DownloadUrl string `yaml:"downloadUrl"` Log string `yaml:"log"` Size uint64 `yaml:"size"` } `yaml:"android"` } `yaml:"app"` Mail struct { Host string `yaml:"host"` Port int `yaml:"port"` User string `yaml:"user"` Pass string `yaml:"pass"` To string `yaml:"to"` } `yaml:"mail"` Alipay struct { NotifyURL string `yaml:"notifyURL"` QuitURL string `yaml:"quitURL"` returnURL string `yaml:"returnURL"` Debug bool `yaml:"debug"` } `yaml:"alipay"` QiNiu struct { MoguCloud struct { AccessKey string `yaml:"accessKey"` SecretKey string `yaml:"secretKey"` SecurityKey string `yaml:"securityKey"` Bucket string `yaml:"bucket"` Domain string `yaml:"domain"` } `yaml:"moguCloud"` } `yaml:"qiNiu"` } func TestGetApolloConfig(t *testing.T) { var wait sync.WaitGroup wait.Add(1) GetApolloConfig("**", "**", config) go func() { for range time.NewTicker(time.Second).C { fmt.Println(config.APP.IOS.Log, time.Now().Format(time_parse.CSTLayout)) } }() wait.Wait() }