123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package conf
- import (
- "errors"
- "flag"
- "go-common/library/cache/memcache"
- "go-common/library/conf"
- "go-common/library/database/bfs"
- "go-common/library/database/elastic"
- "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/permit"
- "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"
- "github.com/BurntSushi/toml"
- )
- //Conf config var
- var (
- ConfPath string
- client *conf.Client
- Conf = &Config{}
- )
- //Config Config
- type Config struct {
- // base
- // ecode
- Ecode *ecode.Config
- // log
- Xlog *log.Config
- Infoc2 *infoc.Config
- InfocBak *infoc.Config
- Verify *verify.Config
- // rpc client
- AccountRPC *warden.ClientConfig
- // rpc client
- ArchiveRPC *rpc.ClientConfig
- // http server config
- HTTPServer *bm.ServerConfig
- // db
- DB *DB
- // memcache
- Memcache *Memcache
- // http client
- HTTPClient *HTTPClient
- // http client of search
- HTTPSearch *HTTPSearch
- // http client of Infoc Data
- HTTPInfoc *HTTPInfoc
- // tracer
- Tracer *trace.Config
- // databus client
- ActionPub *databus.Config
- Host Host
- ManagerAuth *permit.Config
- // elastic config
- Elastic *elastic.Config
- // manager log config
- ManagerLog *databus.Config
- //bfs config
- BFS *bfs.Config
- }
- // DB mysql config struct
- type DB struct {
- DM *sql.Config
- DMMetaWriter *sql.Config
- DMMetaReader *sql.Config
- }
- // Memcache dm memcache
- type Memcache struct {
- Filter *struct {
- *memcache.Config
- }
- Subtitle *struct {
- *memcache.Config
- }
- }
- // DMReport dm report
- type DMReport struct {
- Count int64
- MsgURL string
- MoralURL string
- BlockURL string
- }
- // Host hosts used in dm admin
- type Host struct {
- Videoup string
- API string
- Search string
- Season string
- Message string
- Account string
- Mask string
- Berserker string
- }
- // HTTPClient http client
- type HTTPClient struct {
- *bm.ClientConfig
- JudgeURL string
- ArcInfoURL string
- CidAidsURL string
- TypeInfoURL string
- }
- // HTTPSearch http client of search
- type HTTPSearch struct {
- *bm.ClientConfig
- SearchURL string
- UpdateURL string
- ReportURL string
- UpdateOldURL string
- CountURL string
- }
- // HTTPInfoc http client of Infoc query
- type HTTPInfoc struct {
- *bm.ClientConfig
- InfocQueryURL string
- }
- func init() {
- flag.StringVar(&ConfPath, "conf", "", "config path")
- }
- //Init int config
- 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
- }
|