conf.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package conf
  2. import (
  3. "flag"
  4. "go-common/library/cache/redis"
  5. "go-common/library/conf"
  6. "go-common/library/database/tidb"
  7. ecode "go-common/library/ecode/tip"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/trace"
  11. "go-common/library/queue/databus"
  12. "go-common/library/sync/pipeline"
  13. xtime "go-common/library/time"
  14. "go-common/library/database/hbase.v2"
  15. "github.com/BurntSushi/toml"
  16. )
  17. const (
  18. configKey = "history-job.toml"
  19. )
  20. // global conf
  21. var (
  22. confPath string
  23. Conf = &Config{}
  24. )
  25. // Config service conf
  26. type Config struct {
  27. App *bm.App
  28. Log *log.Config
  29. Tracer *trace.Config
  30. Ecode *ecode.Config
  31. Job *Job
  32. Info *HBaseConfig
  33. HisSub *databus.Config
  34. ServiceHisSub *databus.Config
  35. Sub *databus.Config
  36. BM *bm.ServerConfig
  37. Redis *redis.Config
  38. Merge *pipeline.Config
  39. TiDB *tidb.Config
  40. LongTiDB *tidb.Config
  41. }
  42. // HBaseConfig .
  43. type HBaseConfig struct {
  44. *hbase.Config
  45. WriteTimeout xtime.Duration
  46. ReadTimeout xtime.Duration
  47. }
  48. // Job job.
  49. type Job struct {
  50. URL string
  51. Client *bm.ClientConfig
  52. Expire xtime.Duration
  53. Max int
  54. Batch int
  55. ServiceBatch int
  56. DeleteLimit int
  57. DeleteStartHour int
  58. DeleteEndHour int
  59. DeleteStep xtime.Duration
  60. // 用户最近播放列表长度
  61. CacheLen int
  62. QPSLimit int
  63. IgnoreMsg bool
  64. RetryTime xtime.Duration
  65. }
  66. func init() {
  67. flag.StringVar(&confPath, "conf", "", "config path")
  68. }
  69. // Init init conf
  70. func Init() (err error) {
  71. if confPath == "" {
  72. return configCenter()
  73. }
  74. _, err = toml.DecodeFile(confPath, &Conf)
  75. return
  76. }
  77. func configCenter() (err error) {
  78. var (
  79. ok bool
  80. value string
  81. client *conf.Client
  82. )
  83. if client, err = conf.New(); err != nil {
  84. return
  85. }
  86. if value, ok = client.Value(configKey); !ok {
  87. panic(err)
  88. }
  89. _, err = toml.Decode(value, &Conf)
  90. return
  91. }