conf.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package conf
  2. import (
  3. "errors"
  4. "flag"
  5. "go-common/library/cache/memcache"
  6. "go-common/library/conf"
  7. "go-common/library/database/orm"
  8. ecode "go-common/library/ecode/tip"
  9. "go-common/library/log"
  10. bm "go-common/library/net/http/blademaster"
  11. "go-common/library/net/http/blademaster/middleware/permit"
  12. "go-common/library/net/rpc/warden"
  13. "go-common/library/net/trace"
  14. xtime "go-common/library/time"
  15. "github.com/BurntSushi/toml"
  16. )
  17. var (
  18. confPath string
  19. client *conf.Client
  20. // Conf of config
  21. Conf = &Config{}
  22. )
  23. // Memcache memcache.
  24. type Memcache struct {
  25. *memcache.Config
  26. CmsExpire xtime.Duration
  27. }
  28. // Config def.
  29. type Config struct {
  30. // base
  31. // http
  32. HTTPServer *bm.ServerConfig
  33. // auth
  34. Auth *permit.Config
  35. // db
  36. ORM *orm.Config
  37. // dbshow
  38. ORMShow *orm.Config
  39. // log
  40. Log *log.Config
  41. // tracer
  42. Tracer *trace.Config
  43. // httpsearch
  44. HTTPSearch *HTTPSearch
  45. // Cfg
  46. Cfg *Cfg
  47. // HTTPClient .
  48. HTTPClient *bm.ClientConfig
  49. // URLConf
  50. URLConf *URLConf
  51. // YSTParam
  52. YSTParam *YSTParam
  53. // Bfs
  54. Bfs *Bfs
  55. // grpc
  56. ArcClient *warden.ClientConfig
  57. AccClient *warden.ClientConfig
  58. // Ecode Cfg
  59. Ecode *ecode.Config
  60. //mc
  61. Memcache *Memcache
  62. }
  63. // Cfg def
  64. type Cfg struct {
  65. Playpath string // playurl
  66. AuditRSize int // page size for audit result checking
  67. PlayurlAPI string // pgc playurl api
  68. SearInterMax int
  69. IntervLimit int
  70. PGCTypes []string // pgc types that need to filter archives
  71. PgcNames map[string]string // pgc category name in CN
  72. ModIntMaxSize int // ModIntMaxSize module intervene max size
  73. TypesLoad xtime.Duration // reloading type duratio
  74. UPlayurlAPI string // ugc playurl api
  75. SupportCat *SupportCat
  76. MangoErr string // mango error indication message
  77. LoadSnFre xtime.Duration
  78. RefLabel *RefLabel // refresh label original data frequency
  79. AuditConsult *AuditConsult // audit consult cfg
  80. Hosts *Hosts
  81. Abnormal *Abnormal // abnormal cid export related cfg
  82. EsIdx *EsIdx // es index cfg
  83. }
  84. // EsIdx def.
  85. type EsIdx struct {
  86. UgcIdx *EsCfg
  87. }
  88. // EsCfg def.
  89. type EsCfg struct {
  90. Business string
  91. Index string
  92. }
  93. // RefLabel def.
  94. type RefLabel struct {
  95. Fre xtime.Duration
  96. PgcAPI string // pgc api host
  97. UgcType string
  98. UgcTime string
  99. AllValue string
  100. AllName string
  101. }
  102. // Hosts def.
  103. type Hosts struct {
  104. ESUgc string // ESUgc api
  105. Manager string // manager host
  106. }
  107. // AuditConsult related cfg
  108. type AuditConsult struct {
  109. LikeLimit int
  110. UnshelveNb int
  111. MatchPS int64
  112. }
  113. // Abnormal cid export def
  114. type Abnormal struct {
  115. CriticalCid int64 // 12780000, critical cid for transcoding
  116. AbnormHours int // ugc abnormal cid interval hour
  117. ReloadFre xtime.Duration
  118. ExportTitles []string // export titles
  119. }
  120. // SupportCat means the pgc&ugc types that we support to fill the modules
  121. type SupportCat struct {
  122. PGCTypes []int32
  123. UGCTypes []int32
  124. ReloadFre xtime.Duration
  125. }
  126. // URLConf url conf
  127. type URLConf struct {
  128. GetRemotePanelUrl string
  129. SyncPanelUrl string
  130. }
  131. // YSTParam yst config param
  132. type YSTParam struct {
  133. QueryPanelType string
  134. InsertPanelType string
  135. Source string
  136. Insert string
  137. Update string
  138. }
  139. // Bfs struct
  140. type Bfs struct {
  141. Key string
  142. Secret string
  143. Host string
  144. Timeout int
  145. Bucket string
  146. }
  147. // HTTPSearch http client of search
  148. type HTTPSearch struct {
  149. *bm.ClientConfig
  150. FullURL string
  151. }
  152. func local() (err error) {
  153. _, err = toml.DecodeFile(confPath, &Conf)
  154. return
  155. }
  156. func remote() (err error) {
  157. if client, err = conf.New(); err != nil {
  158. return
  159. }
  160. if err = load(); err != nil {
  161. return
  162. }
  163. go func() {
  164. for range client.Event() {
  165. log.Info("config reload")
  166. if load() != nil {
  167. log.Error("config reload error (%v)", err)
  168. }
  169. }
  170. }()
  171. return
  172. }
  173. func load() (err error) {
  174. var (
  175. s string
  176. ok bool
  177. tmpConf *Config
  178. )
  179. if s, ok = client.Toml2(); !ok {
  180. return errors.New("load config center error")
  181. }
  182. if _, err = toml.Decode(s, &tmpConf); err != nil {
  183. return errors.New("could not decode config")
  184. }
  185. *Conf = *tmpConf
  186. return
  187. }
  188. func init() {
  189. flag.StringVar(&confPath, "conf", "", "default config path")
  190. }
  191. // Init int config
  192. func Init() error {
  193. if confPath != "" {
  194. return local()
  195. }
  196. return remote()
  197. }