conf.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package conf
  2. import (
  3. "flag"
  4. "go-common/library/cache/memcache"
  5. "go-common/library/cache/redis"
  6. "go-common/library/conf"
  7. "go-common/library/database/elastic"
  8. "go-common/library/database/sql"
  9. ecode "go-common/library/ecode/tip"
  10. "go-common/library/log"
  11. bm "go-common/library/net/http/blademaster"
  12. bauth "go-common/library/net/http/blademaster/middleware/permit"
  13. "go-common/library/net/http/blademaster/middleware/verify"
  14. "go-common/library/net/rpc"
  15. "go-common/library/net/rpc/warden"
  16. "go-common/library/net/trace"
  17. "go-common/library/queue/databus"
  18. "go-common/library/time"
  19. "github.com/BurntSushi/toml"
  20. )
  21. var (
  22. // ConfPath config toml file path for reply admin project
  23. ConfPath string
  24. // Conf global config instance
  25. Conf *Config
  26. )
  27. // Config config.
  28. type Config struct {
  29. // base
  30. // ecode
  31. Ecode *ecode.Config
  32. // log
  33. Log *log.Config
  34. // tracer
  35. Tracer *trace.Config
  36. // verify
  37. Verify *verify.Config
  38. // http
  39. HTTPServer *bm.ServerConfig
  40. // db
  41. DB *DB
  42. // memcache
  43. Memcache *Memcache
  44. // Redis
  45. Redis *Redis
  46. // http client
  47. HTTPClient *bm.ClientConfig
  48. DrawyooHTTPClient *bm.ClientConfig
  49. // reply
  50. Reply *Reply
  51. // host
  52. Host *Host
  53. // Stats
  54. StatTypes map[string]int32
  55. Weight *Weight
  56. RPCClient2 *RPCClient2
  57. Databus *Databus
  58. ManagerAuth *bauth.Config
  59. ManagerReport *databus.Config
  60. Es *elastic.Config
  61. ThumbupClient *warden.ClientConfig
  62. AccountClient *warden.ClientConfig
  63. }
  64. // Databus databus.
  65. type Databus struct {
  66. Event *databus.Config
  67. Stats *databus.Config
  68. }
  69. // RPCClient2 rpc client.
  70. type RPCClient2 struct {
  71. Account *rpc.ClientConfig
  72. Archive *rpc.ClientConfig
  73. Article *rpc.ClientConfig
  74. Assist *rpc.ClientConfig
  75. Thumbup *rpc.ClientConfig
  76. Relation *rpc.ClientConfig
  77. }
  78. // Weight weight.
  79. type Weight struct {
  80. Like int32
  81. Hate int32
  82. }
  83. // Stats stats.
  84. type Stats struct {
  85. *databus.Config
  86. Type int32
  87. Field string
  88. }
  89. // Redis redis.
  90. type Redis struct {
  91. *redis.Config
  92. Expire time.Duration
  93. }
  94. // Reply reply.
  95. type Reply struct {
  96. PageNum int
  97. PageSize int
  98. LikeWeight int32
  99. HateWeight int32
  100. // 大忽悠事件删除评论的管理员
  101. AdminName []string
  102. // 针对大忽悠的跳转链接
  103. Link string
  104. // 针对大忽悠时间的特殊稿件
  105. Oids []int64
  106. Tps []int32
  107. }
  108. // Host host.
  109. type Host struct {
  110. Search string
  111. }
  112. // DB db.
  113. type DB struct {
  114. Reply *sql.Config
  115. ReplySlave *sql.Config
  116. }
  117. // Memcache memcache.
  118. type Memcache struct {
  119. *memcache.Config
  120. Expire time.Duration
  121. }
  122. func init() {
  123. flag.StringVar(&ConfPath, "conf", "", "config path")
  124. }
  125. // Init inti config.
  126. func Init() (err error) {
  127. if ConfPath == "" {
  128. return configCenter()
  129. }
  130. _, err = toml.DecodeFile(ConfPath, &Conf)
  131. return
  132. }
  133. func configCenter() (err error) {
  134. var (
  135. ok bool
  136. value string
  137. client *conf.Client
  138. )
  139. if client, err = conf.New(); err != nil {
  140. return
  141. }
  142. if value, ok = client.Toml2(); !ok {
  143. panic(err)
  144. }
  145. _, err = toml.Decode(value, &Conf)
  146. return
  147. }