conf.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package conf
  2. import (
  3. "errors"
  4. "flag"
  5. "go-common/app/admin/ep/melloi/model"
  6. "go-common/library/cache/memcache"
  7. "go-common/library/cache/redis"
  8. "go-common/library/conf"
  9. "go-common/library/database/orm"
  10. ecode "go-common/library/ecode/tip"
  11. "go-common/library/log"
  12. bm "go-common/library/net/http/blademaster"
  13. "go-common/library/net/http/blademaster/middleware/permit"
  14. "go-common/library/net/rpc/warden"
  15. "go-common/library/net/trace"
  16. "github.com/BurntSushi/toml"
  17. )
  18. var (
  19. confPath string
  20. client *conf.Client
  21. // Conf config
  22. Conf = &Config{}
  23. )
  24. // Config .
  25. type Config struct {
  26. Log *log.Config
  27. //BM *HTTPServers
  28. Tracer *trace.Config
  29. Redis *redis.Config
  30. Memcache *memcache.Config
  31. Ecode *ecode.Config
  32. ORM *orm.Config
  33. Permit *permit.Config2
  34. PermitGRPC *warden.ClientConfig
  35. HTTPClient *bm.ClientConfig
  36. ServiceTree *model.TreeConf
  37. Dapper *Dapper
  38. BfsConf *model.BFSConf
  39. ServiceCluster *model.ClusterConf
  40. Melloi *Melloi
  41. BM *bm.ServerConfig
  42. Wechat *Wechat
  43. Mail *Mail
  44. Paas *Paas
  45. Grpc *Grpc
  46. Jmeter *Jmeter
  47. DockerStatus *DockerStatus
  48. }
  49. // Dapper conf
  50. type Dapper struct {
  51. Host string
  52. }
  53. // DockerStatus conf
  54. type DockerStatus struct {
  55. Host string // ip
  56. Port int // port
  57. }
  58. //Paas conf
  59. type Paas struct {
  60. APIToken string // PaaS token获取
  61. PlatformID string //PaaS token获取
  62. BusinessUnit string //BU
  63. Project string //项目
  64. App string //应用
  65. Env string //环境
  66. Image string //镜像名称
  67. ImageVersion string //镜像版本
  68. Volumes string //PaaS 创建job
  69. ResourcePoolID string //PaaS 创建job
  70. Completions int //PaaS 创建job
  71. RetriesLimit int //PaaS 创建job
  72. NetworkID int
  73. ClusterID int
  74. TreeID int //服务树ID
  75. HostInfo string //PaaS 创建job
  76. Action string //paas 查询容器cpu
  77. PublicKey string //key
  78. Signature int //paas 查询容器cpu
  79. DataSource string //数据源
  80. Query string //paas 查询容器cpu语句
  81. CPUCore int //cpu 核数
  82. CPUCoreDebug int //debug cpu 核数
  83. }
  84. //Melloi melloi config
  85. type Melloi struct {
  86. AppkeyProd string //线上appkey
  87. SecretProd string //线上sceret
  88. AppkeyUat string //uat appkey
  89. SecretUat string //uat secret
  90. Executor []string //白名单
  91. CheckTime bool //是否校验压测时间
  92. MaxFileSize int64
  93. DefaultHost string
  94. MaxDowloadSize int64
  95. DefaultFusing int //默认熔断成功率
  96. DefaultBusinessRate int //默认业务熔断阈值
  97. Recent int //最近的qps取数
  98. }
  99. //Wechat wechat config
  100. type Wechat struct {
  101. Host string //微信通知id
  102. Chatid string
  103. Msgtype string
  104. Safe int
  105. SendMessage bool //是否发送通知
  106. }
  107. // Mail mail
  108. type Mail struct {
  109. Host string
  110. Port int
  111. Username string
  112. Password string
  113. NoticeOwner []string
  114. }
  115. // Grpc grpc
  116. type Grpc struct {
  117. ProtoJavaPluginPath string
  118. }
  119. // Jmeter jmeter
  120. type Jmeter struct {
  121. JmeterExtLibPath string
  122. JmeterExtLibPathContainer string
  123. GRPCTemplatePath string
  124. TestTimeLimit int
  125. ThreadGroupPort int //执行生成线程组的接口的端口号
  126. JmeterScUcodedTmp string
  127. JmeterScTmp string
  128. JmeterSampleTmp string
  129. JmeterSamplePostTmp string
  130. JmeterThGroupTmp string
  131. JmeterThGroupPostTmp string
  132. JmeterThGroupDuliTmp string
  133. JmeterThGroupPostDuliTmp string
  134. JmeterSceneTmp string
  135. JSONExtractorTmp string
  136. }
  137. // init init
  138. func init() {
  139. flag.StringVar(&confPath, "conf", "", "default config path")
  140. }
  141. // Init init conf
  142. func Init() error {
  143. if confPath != "" {
  144. return local()
  145. }
  146. return remote()
  147. }
  148. // local local
  149. func local() (err error) {
  150. _, err = toml.DecodeFile(confPath, &Conf)
  151. return
  152. }
  153. // remote remote
  154. func remote() (err error) {
  155. if client, err = conf.New(); err != nil {
  156. return
  157. }
  158. return load()
  159. }
  160. // load load
  161. func load() (err error) {
  162. var (
  163. s string
  164. ok bool
  165. tmpConf *Config
  166. )
  167. if s, ok = client.Value("melloi.toml"); !ok {
  168. return errors.New("load config center error")
  169. }
  170. if _, err = toml.Decode(s, &tmpConf); err != nil {
  171. return errors.New("could not decode config")
  172. }
  173. *Conf = *tmpConf
  174. return
  175. }