conf.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/sql"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/rpc"
  11. "go-common/library/queue/databus"
  12. "go-common/library/time"
  13. "github.com/BurntSushi/toml"
  14. )
  15. var (
  16. confPath string
  17. // Conf .
  18. Conf *Config
  19. )
  20. // Config .
  21. type Config struct {
  22. // base
  23. // fav
  24. Fav *Fav
  25. // log
  26. Log *log.Config
  27. // db
  28. DB *DB
  29. // memcache
  30. Memcache *Memcache
  31. // redis
  32. Redis *Redis
  33. // stat fav databus
  34. StatFavDatabus *StatFavDatabus
  35. // job databus
  36. JobDatabus *databus.Config
  37. // BinlogDatabus databus.
  38. BinlogDatabus *databus.Config
  39. // rpc client
  40. RPCClient2 *RPC
  41. // BM blademaster
  42. BM *bm.ServerConfig
  43. // StatMerge for bnj
  44. StatMerge *StatMerge
  45. // playlist stat
  46. FavStatDatabus *databus.Config
  47. ShareStatDatabus *databus.Config
  48. MediaListCntDatabus *databus.Config
  49. // http client
  50. HTTPClient *bm.ClientConfig
  51. }
  52. // Fav favorite
  53. type Fav struct {
  54. Proc int64
  55. MaxPageSize int
  56. CleanCDTime time.Duration
  57. SleepTime time.Duration
  58. GreyMod int64
  59. WhiteMids []int64
  60. }
  61. // StatMerge .
  62. type StatMerge struct {
  63. Business int
  64. Target int64
  65. Sources []int64
  66. }
  67. // RPC rpc cliens.
  68. type RPC struct {
  69. Archive *rpc.ClientConfig
  70. Article *rpc.ClientConfig
  71. Coin *rpc.ClientConfig
  72. }
  73. // DB mysql.
  74. type DB struct {
  75. // favorite db
  76. Fav *sql.Config
  77. Read *sql.Config
  78. }
  79. // Redis redis conf.
  80. type Redis struct {
  81. *redis.Config
  82. Expire time.Duration
  83. IPExpire time.Duration
  84. BuvidExpire time.Duration
  85. }
  86. // Memcache mc conf.
  87. type Memcache struct {
  88. *memcache.Config
  89. Expire time.Duration
  90. }
  91. // StatsDatabus stats.
  92. type StatsDatabus struct {
  93. *databus.Config
  94. Field string
  95. Type int8
  96. }
  97. // StatFavDatabus new stats.
  98. type StatFavDatabus struct {
  99. *databus.Config
  100. Consumers map[string]int8
  101. }
  102. // init
  103. func init() {
  104. flag.StringVar(&confPath, "conf", "", "config path")
  105. }
  106. // Init init conf
  107. func Init() (err error) {
  108. if confPath == "" {
  109. return configCenter()
  110. }
  111. _, err = toml.DecodeFile(confPath, &Conf)
  112. return
  113. }
  114. // configCenter remote config.
  115. func configCenter() (err error) {
  116. var (
  117. ok bool
  118. value string
  119. client *conf.Client
  120. )
  121. if client, err = conf.New(); err != nil {
  122. return
  123. }
  124. if value, ok = client.Toml2(); !ok {
  125. panic(err)
  126. }
  127. _, err = toml.Decode(value, &Conf)
  128. return
  129. }