conf.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package conf
  2. import (
  3. "errors"
  4. "flag"
  5. "go-common/app/interface/openplatform/article/model"
  6. "go-common/library/cache/memcache"
  7. "go-common/library/cache/redis"
  8. "go-common/library/conf"
  9. "go-common/library/database/sql"
  10. ecode "go-common/library/ecode/tip"
  11. "go-common/library/log"
  12. "go-common/library/log/infoc"
  13. bm "go-common/library/net/http/blademaster"
  14. "go-common/library/net/http/blademaster/middleware/antispam"
  15. "go-common/library/net/http/blademaster/middleware/auth"
  16. "go-common/library/net/http/blademaster/middleware/verify"
  17. "go-common/library/net/rpc"
  18. "go-common/library/net/rpc/warden"
  19. "go-common/library/net/trace"
  20. "go-common/library/queue/databus"
  21. "go-common/library/time"
  22. "github.com/BurntSushi/toml"
  23. hbase "go-common/library/database/hbase.v2"
  24. )
  25. // global var
  26. var (
  27. confPath string
  28. client *conf.Client
  29. // Conf config
  30. Conf = &Config{}
  31. )
  32. // Config config set
  33. type Config struct {
  34. // base
  35. // elk
  36. Log *log.Config
  37. // BM
  38. BM *bm.ServerConfig
  39. // HTTPClient .
  40. HTTPClient *bm.ClientConfig
  41. MessageHTTPClient *bm.ClientConfig
  42. // tracer
  43. Tracer *trace.Config
  44. // auth
  45. Auth *auth.Config
  46. // verify
  47. Verify *verify.Config
  48. // redis
  49. Redis *redis.Config
  50. // memcache
  51. Memcache *Memcache
  52. // MySQL
  53. MySQL MySQL
  54. // rpc
  55. AccountRPC *rpc.ClientConfig
  56. TagRPC *rpc.ClientConfig
  57. FavRPC *rpc.ClientConfig
  58. ArcRPC *rpc.ClientConfig
  59. CoinRPC *rpc.ClientConfig
  60. ResRPC *rpc.ClientConfig
  61. ThumbupRPC *rpc.ClientConfig
  62. FilterRPC *rpc.ClientConfig
  63. HistoryRPC *rpc.ClientConfig
  64. SearchRPC *warden.ClientConfig
  65. // databus
  66. StatDatabus *databus.Config
  67. // infoc log2
  68. DisplayInfoc *infoc.Config
  69. ClickInfoc *infoc.Config
  70. AIClickInfoc *infoc.Config
  71. ShowInfoc *infoc.Config
  72. CheatInfoc *infoc.Config
  73. // ecode
  74. Ecode *ecode.Config
  75. //RankCategories .
  76. RankCategories []*model.RankCategory
  77. //Message
  78. Message Message
  79. Cards Cards
  80. //hbase
  81. HBase *hbase.Config
  82. // BFS
  83. BFS *BFS
  84. // Antispam
  85. Antispam *antispam.Config
  86. // DegradeConfig
  87. DegradeConfig *DegradeConfig
  88. // artcile
  89. Article Article
  90. //Berserker
  91. Berserker Berserker
  92. //Sentinel
  93. Sentinel *Sentinel
  94. }
  95. //Sentinel .
  96. type Sentinel struct {
  97. EnableSentinel int `json:"enableSentinel"`
  98. DurationSample int `json:"durationSample"`
  99. MonitorCountSample int `json:"monitorCountSample"`
  100. MonitorRateSample int `json:"monitorRateSample"`
  101. DebugSample int `json:"debugSample"`
  102. }
  103. // Berserker .
  104. type Berserker struct {
  105. AppKey string
  106. AppSecret string
  107. URL string
  108. }
  109. // Memcache config
  110. type Memcache struct {
  111. *memcache.Config
  112. ArticleExpire time.Duration
  113. StatsExpire time.Duration
  114. LikeExpire time.Duration
  115. CardsExpire time.Duration
  116. SubmitExpire time.Duration
  117. ListArtsExpire time.Duration
  118. ListExpire time.Duration
  119. ArtListExpire time.Duration
  120. UpListsExpire time.Duration
  121. ListReadExpire time.Duration
  122. HotspotExpire time.Duration
  123. AuthorExpire time.Duration
  124. ArticlesIDExpire time.Duration
  125. ArticleTagExpire time.Duration
  126. UpStatDailyExpire time.Duration
  127. }
  128. // MySQL config
  129. type MySQL struct {
  130. Article *sql.Config
  131. }
  132. // Cards config
  133. type Cards struct {
  134. TicketURL string
  135. MallURL string
  136. AudioURL string
  137. BangumiURL string
  138. }
  139. // BFS bfs config
  140. type BFS struct {
  141. Timeout time.Duration
  142. MaxFileSize int
  143. Bucket string
  144. URL string
  145. Method string
  146. Key string
  147. Secret string
  148. }
  149. // DegradeConfig .
  150. type DegradeConfig struct {
  151. Expire int32
  152. Memcache *memcache.Config
  153. }
  154. // Article article config
  155. type Article struct {
  156. ExpireUpper time.Duration
  157. ExpireArtLikes time.Duration
  158. ExpireSortArts time.Duration
  159. TTLSortArts time.Duration
  160. ExpireRank time.Duration
  161. TTLRank time.Duration
  162. ExpireMaxLike time.Duration
  163. ExpireHotspot time.Duration
  164. CreationDefaultSize int
  165. CreationMaxSize int
  166. UpperDraftLimit int
  167. UpperArticleLimit int
  168. UpdateRecommendsInteval time.Duration
  169. MaxRecommendPnSize int64
  170. MaxRecommendPsSize int64
  171. MaxUpperListPsSize int64
  172. MaxArchives int
  173. MaxComplaintReasonLimit int64
  174. MaxArticleMetas int
  175. MaxApplyContentLimit int64
  176. MaxApplyCategoryLimit int64
  177. MaxLikeMidLen int
  178. RecommendAidLen int
  179. SortLimitTime time.Duration
  180. UpdateBannersInteval time.Duration
  181. BannerIDs []int
  182. ActBannerIDs []int
  183. RecommendRegionLen int
  184. SkyHorseRecommendRegionLen int
  185. RankHost string
  186. MessageMids []int64
  187. MaxContentSize int
  188. MaxContentLength int
  189. MinContentLength int
  190. ActAddURI string
  191. ActDelURI string
  192. ActURI string
  193. ListLimit int
  194. ListArtsLimit int
  195. AppCategoryName string
  196. AppCategoryURL string
  197. SkyHorseURL string
  198. SkyHorseGray []int64
  199. SkyHorseGrayUsers []int64
  200. ListDefaultImage string
  201. RecommendAuthors int
  202. ExpireReadPing time.Duration
  203. ExpireReadSet time.Duration
  204. Media []int64
  205. EditTimes int
  206. RecommendAuthorsURL string
  207. }
  208. // Message .
  209. type Message struct {
  210. URL string
  211. MC string
  212. }
  213. func init() {
  214. flag.StringVar(&confPath, "conf", "", "default config path")
  215. }
  216. // Init init conf
  217. func Init() error {
  218. if confPath != "" {
  219. return local()
  220. }
  221. return remote()
  222. }
  223. func local() (err error) {
  224. _, err = toml.DecodeFile(confPath, &Conf)
  225. return
  226. }
  227. func remote() (err error) {
  228. if client, err = conf.New(); err != nil {
  229. return
  230. }
  231. err = load()
  232. return
  233. }
  234. func load() (err error) {
  235. var (
  236. s string
  237. ok bool
  238. tmpConf *Config
  239. )
  240. if s, ok = client.Toml2(); !ok {
  241. return errors.New("load config center error")
  242. }
  243. if _, err = toml.Decode(s, &tmpConf); err != nil {
  244. return errors.New("could not decode config")
  245. }
  246. *Conf = *tmpConf
  247. return
  248. }