conf.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package conf
  2. import (
  3. "flag"
  4. "go-common/library/cache/redis"
  5. "go-common/library/conf"
  6. ecode "go-common/library/ecode/tip"
  7. xlog "go-common/library/log"
  8. "go-common/library/log/infoc"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/http/blademaster/middleware/auth"
  11. "go-common/library/net/http/blademaster/middleware/verify"
  12. "go-common/library/net/rpc"
  13. "go-common/library/net/rpc/warden"
  14. "go-common/library/net/trace"
  15. "go-common/library/queue/databus"
  16. xtime "go-common/library/time"
  17. "go-common/library/database/hbase.v2"
  18. "github.com/BurntSushi/toml"
  19. )
  20. const (
  21. configKey = "history.toml"
  22. )
  23. var (
  24. confPath string
  25. // Conf global
  26. Conf = &Config{}
  27. )
  28. // HBaseConfig ...
  29. type HBaseConfig struct {
  30. *hbase.Config
  31. WriteTimeout xtime.Duration
  32. ReadTimeout xtime.Duration
  33. }
  34. // Config service conf
  35. type Config struct {
  36. Tracer *trace.Config
  37. History *History
  38. BM *bm.ServerConfig
  39. RPCClient2 *RPC
  40. Toview *Redis
  41. Redis *Redis
  42. Xlog *xlog.Config
  43. Info *HBaseConfig
  44. DataBus *Databus
  45. Auth *auth.Config
  46. Verify *verify.Config
  47. Collector *infoc.Config
  48. Ecode *ecode.Config
  49. RPCServer *rpc.ServerConfig
  50. GRPC *warden.ServerConfig
  51. ThirdBusines *ThirdBusines
  52. Report *databus.Config
  53. }
  54. // History history.
  55. type History struct {
  56. Max int
  57. Total int
  58. Cache int
  59. Page int
  60. Size int
  61. Ticker xtime.Duration
  62. Pub bool
  63. ConsumeSize int
  64. Migration bool
  65. Rate int64
  66. Mids []int64
  67. }
  68. // ThirdBusines Bangumi favorite.
  69. type ThirdBusines struct {
  70. BangumiV2URL string
  71. SeasonURL string
  72. HTTPClient *bm.ClientConfig
  73. }
  74. // Databus .
  75. type Databus struct {
  76. PlayPro *databus.Config
  77. Merge *databus.Config
  78. Experience *databus.Config
  79. Pub *databus.Config
  80. }
  81. // Redis redis.
  82. type Redis struct {
  83. *redis.Config
  84. Expire xtime.Duration
  85. }
  86. // RPC rpc.
  87. type RPC struct {
  88. Archive *rpc.ClientConfig
  89. Favorite *rpc.ClientConfig
  90. History *warden.ClientConfig
  91. }
  92. func init() {
  93. flag.StringVar(&confPath, "conf", "", "config path")
  94. }
  95. // Init init conf
  96. func Init() (err error) {
  97. if confPath == "" {
  98. return configCenter()
  99. }
  100. _, err = toml.DecodeFile(confPath, &Conf)
  101. return
  102. }
  103. func configCenter() (err error) {
  104. var (
  105. ok bool
  106. value string
  107. client *conf.Client
  108. )
  109. if client, err = conf.New(); err != nil {
  110. return
  111. }
  112. if value, ok = client.Value(configKey); !ok {
  113. panic(err)
  114. }
  115. _, err = toml.Decode(value, &Conf)
  116. return
  117. }