123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- package conf
- import (
- "errors"
- "flag"
- xtime "time"
- "go-common/app/interface/main/player/model"
- "go-common/library/conf"
- "go-common/library/database/sql"
- ecode "go-common/library/ecode/tip"
- "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/time"
- "github.com/BurntSushi/toml"
- )
- // global var
- var (
- confPath string
- client *conf.Client
- Conf = &Config{}
- )
- // Config is service conf.
- type Config struct {
- // 广播
- Broadcast Broadcast
- // policy
- Policy *model.Policy
- // policy items
- Pitem []*model.Pitem
- // 拜年祭
- Matsuri Matsuri
- // XLog
- XLog *log.Config
- // ecode
- Ecode *ecode.Config
- // host
- Host *Host
- // tracer
- Tracer *trace.Config
- // auth
- Auth *auth.Config
- // verify
- Verify *verify.Config
- // bm
- BM *HTTPServers
- // mysql
- MySQL *MySQL
- // rpc
- ArchiveRPC *rpc.ClientConfig
- AccountRPC *rpc.ClientConfig
- HistoryRPC *rpc.ClientConfig
- AssistRPC *rpc.ClientConfig
- ResourceRPC *rpc.ClientConfig
- Dm2RPC *rpc.ClientConfig
- LocRPC *rpc.ClientConfig
- TagRPC *rpc.ClientConfig
- // HTTPClient
- HTTPClient *bm.ClientConfig
- // Rule
- Rule *Rule
- Tick *Tick
- // Infoc2
- Infoc2 *infoc.Config
- // PlayURLToken
- PlayURLToken *PlayURLToken
- // grpc client
- AccClient *warden.ClientConfig
- ArcClient *warden.ClientConfig
- UGCPayClient *warden.ClientConfig
- // icon
- Icon *icon
- // bnj2019
- Bnj2019 *bnj2019
- }
- // Tick tick time.
- type Tick struct {
- // tick time
- CarouselTick time.Duration
- ParamTick time.Duration
- IconTick time.Duration
- }
- // Rule rules
- type Rule struct {
- // timeout
- VsTimeout time.Duration
- NoAssistMid int64
- VipQn []int
- LoginQn int
- MaxFreeQn int
- AutoQn int
- PlayurlGray int64
- }
- // Host is host info
- type Host struct {
- APICo string
- AccCo string
- PlayurlCo string
- H5Playurl string
- HighPlayurl string
- }
- // MySQL mysql.
- type MySQL struct {
- Show *sql.Config
- }
- // Broadcast breadcast.
- type Broadcast struct {
- TCPAddr string
- WsAddr string
- WssAddr string
- Begin string
- End string
- }
- // Matsuri matsuri.
- type Matsuri struct {
- PastID int64
- MatID int64
- MatTime string
- Tick time.Duration
- }
- // PlayURLToken playurl auth token.
- type PlayURLToken struct {
- Secret string
- PlayerToken string
- }
- // HTTPServers bm servers config.
- type HTTPServers struct {
- Outer *bm.ServerConfig
- }
- type bnj2019 struct {
- BnjMainAid int64
- BnjListAids []int64
- BnjTick time.Duration
- }
- type icon struct {
- Start xtime.Time
- End xtime.Time
- URL1 string
- Hash1 string
- URL2 string
- Hash2 string
- }
- func init() {
- flag.StringVar(&confPath, "conf", "", "config path")
- }
- // Init init conf
- func Init() error {
- if confPath != "" {
- return local()
- }
- return remote()
- }
- func local() (err error) {
- _, err = toml.DecodeFile(confPath, &Conf)
- return
- }
- func remote() (err error) {
- if client, err = conf.New(); err != nil {
- return
- }
- if err = load(); err != nil {
- return
- }
- go func() {
- for range client.Event() {
- log.Info("config reload")
- if load() != nil {
- log.Error("config reload error (%v)", err)
- }
- }
- }()
- return
- }
- func load() (err error) {
- var (
- s string
- ok bool
- tmpConf *Config
- )
- if s, ok = client.Toml2(); !ok {
- return errors.New("load config center error")
- }
- if _, err = toml.Decode(s, &tmpConf); err != nil {
- return errors.New("could not decode config")
- }
- *Conf = *tmpConf
- return
- }
|