123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- package conf
- import (
- "errors"
- "flag"
- "go-common/app/interface/main/app-feed/model/feed"
- "go-common/library/cache/memcache"
- "go-common/library/cache/redis"
- "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/rpc"
- "go-common/library/net/rpc/warden"
- "go-common/library/net/trace"
- "go-common/library/queue/databus"
- xtime "go-common/library/time"
- "github.com/BurntSushi/toml"
- )
- var (
- confPath string
- Conf = &Config{}
- client *conf.Client
- )
- type Config struct {
- // env
- Env string
- // infoc log2
- ShowInfoc2 *infoc.Config
- TagInfoc2 *infoc.Config
- RedirectInfoc2 *infoc.Config
- // show XLog
- XLog *log.Config
- // tick time
- Tick xtime.Duration
- // tracer
- Tracer *trace.Config
- // httpClinet
- HTTPClient *bm.ClientConfig
- // httpAsyn
- HTTPClientAsyn *bm.ClientConfig
- // httpData
- HTTPData *bm.ClientConfig
- // httpTag
- HTTPTag *bm.ClientConfig
- // httpAd
- HTTPAd *bm.ClientConfig
- // httpActivity
- HTTPActivity *bm.ClientConfig
- // httpBangumi
- HTTPBangumi *bm.ClientConfig
- // httpShow
- HTTPShow *bm.ClientConfig
- // httpDynamic
- HTTPDynamic *bm.ClientConfig
- // httpClinet
- HTTPSearch *bm.ClientConfig
- // rpc Location
- LocationRPC *rpc.ClientConfig
- // http
- BM *HTTPServers
- // host
- Host *Host
- // db
- MySQL *MySQL
- // redis
- Redis *Redis
- // mc
- Memcache *Memcache
- // rpc client
- AccountRPC *rpc.ClientConfig
- RelationRPC *rpc.ClientConfig
- ArchiveRPC *rpc.ClientConfig
- FeedRPC *rpc.ClientConfig
- TagRPC *rpc.ClientConfig
- ArticleRPC *rpc.ClientConfig
- ResourceRPC *rpc.ClientConfig
- // databus
- DislikeDatabus *databus.Config
- // ecode
- Ecode *ecode.Config
- // feed
- Feed *Feed
- // bnj2018
- Bnj *BnjConfig
- // BroadcastRPC grpc
- PGCRPC *warden.ClientConfig
- // autoplay mids
- AutoPlayMids []int64
- }
- // HTTPServers Http Servers
- type HTTPServers struct {
- Outer *bm.ServerConfig
- }
- // BnjConfig 2018拜年祭配置
- type BnjConfig struct {
- TabImg string
- TabID int64
- BeginTime string
- }
- type Host struct {
- LiveAPI string
- Bangumi string
- Data string
- Hetongzi string
- APICo string
- Ad string
- Activity string
- Rank string
- Show string
- Dynamic string
- DynamicCo string
- BigData string
- Search string
- }
- type MySQL struct {
- Show *sql.Config
- Manager *sql.Config
- }
- type Redis struct {
- Feed *struct {
- *redis.Config
- ExpireRecommend xtime.Duration
- ExpireBlack xtime.Duration
- }
- Upper *struct {
- *redis.Config
- ExpireUpper xtime.Duration
- }
- }
- type Memcache struct {
- Feed *struct {
- *memcache.Config
- ExpireArchive xtime.Duration
- }
- Cache *struct {
- *memcache.Config
- ExpireCache xtime.Duration
- }
- }
- type Feed struct {
- // feed
- FeedCacheCount int
- LiveFeedCount int
- // index
- Index *Index
- // ad
- CMResource map[string]int64
- }
- type Index struct {
- Count int
- IPadCount int
- MoePosition int
- FollowPosition int
- // only archive for data disaster recovery
- Abnormal bool
- Interest []string
- FollowMode *feed.FollowMode
- }
- func init() {
- flag.StringVar(&confPath, "conf", "", "default 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
- }
- client.Watch("app-feed.toml")
- 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
- }
|