123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package conf
- import (
- "flag"
- "go-common/library/cache/redis"
- "go-common/library/conf"
- ecode "go-common/library/ecode/tip"
- xlog "go-common/library/log"
- "go-common/library/log/infoc"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/http/blademaster/middleware/auth"
- "go-common/library/net/http/blademaster/middleware/verify"
- "go-common/library/net/rpc"
- "go-common/library/net/rpc/warden"
- "go-common/library/net/trace"
- "go-common/library/queue/databus"
- xtime "go-common/library/time"
- "go-common/library/database/hbase.v2"
- "github.com/BurntSushi/toml"
- )
- const (
- configKey = "history.toml"
- )
- var (
- confPath string
- // Conf global
- Conf = &Config{}
- )
- // HBaseConfig ...
- type HBaseConfig struct {
- *hbase.Config
- WriteTimeout xtime.Duration
- ReadTimeout xtime.Duration
- }
- // Config service conf
- type Config struct {
- Tracer *trace.Config
- History *History
- BM *bm.ServerConfig
- RPCClient2 *RPC
- Toview *Redis
- Redis *Redis
- Xlog *xlog.Config
- Info *HBaseConfig
- DataBus *Databus
- Auth *auth.Config
- Verify *verify.Config
- Collector *infoc.Config
- Ecode *ecode.Config
- RPCServer *rpc.ServerConfig
- GRPC *warden.ServerConfig
- ThirdBusines *ThirdBusines
- Report *databus.Config
- }
- // History history.
- type History struct {
- Max int
- Total int
- Cache int
- Page int
- Size int
- Ticker xtime.Duration
- Pub bool
- ConsumeSize int
- Migration bool
- Rate int64
- Mids []int64
- }
- // ThirdBusines Bangumi favorite.
- type ThirdBusines struct {
- BangumiV2URL string
- SeasonURL string
- HTTPClient *bm.ClientConfig
- }
- // Databus .
- type Databus struct {
- PlayPro *databus.Config
- Merge *databus.Config
- Experience *databus.Config
- Pub *databus.Config
- }
- // Redis redis.
- type Redis struct {
- *redis.Config
- Expire xtime.Duration
- }
- // RPC rpc.
- type RPC struct {
- Archive *rpc.ClientConfig
- Favorite *rpc.ClientConfig
- History *warden.ClientConfig
- }
- func init() {
- flag.StringVar(&confPath, "conf", "", "config path")
- }
- // Init init conf
- func Init() (err error) {
- if confPath == "" {
- return configCenter()
- }
- _, err = toml.DecodeFile(confPath, &Conf)
- return
- }
- func configCenter() (err error) {
- var (
- ok bool
- value string
- client *conf.Client
- )
- if client, err = conf.New(); err != nil {
- return
- }
- if value, ok = client.Value(configKey); !ok {
- panic(err)
- }
- _, err = toml.Decode(value, &Conf)
- return
- }
|