123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- package conf
- import (
- "errors"
- "flag"
- "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"
- )
- // conf init.
- var (
- confPath string
- client *conf.Client
- // Conf config
- Conf = &Config{}
- )
- // Config struct
- type Config struct {
- // Local cache
- LocalCache bool
- // interface XLog
- XLog *log.Config
- // tick time
- Tick xtime.Duration
- // tracer
- Tracer *trace.Config
- // databus
- UseractPub *databus.Config
- // httpClinet
- HTTPClient *bm.ClientConfig
- // httpIm9
- HTTPIm9 *bm.ClientConfig
- // httpSearch
- HTTPSearch *bm.ClientConfig
- // httpWrite
- HTTPWrite *bm.ClientConfig
- // httpLive
- HTTPLive *bm.ClientConfig
- // httpbangumi
- HTTPBangumi *bm.ClientConfig
- // httpbplus
- HTTPBPlus *bm.ClientConfig
- // httpgame
- HTTPGame *bm.ClientConfig
- // http
- BM *HTTPServers
- // host
- Host *Host
- // rpc client
- AccountRPC *rpc.ClientConfig
- ArchiveRPC *rpc.ClientConfig
- TagRPC *rpc.ClientConfig
- ArticleRPC *rpc.ClientConfig
- RelationRPC *rpc.ClientConfig
- ThumbupRPC *rpc.ClientConfig
- HistoryRPC *rpc.ClientConfig
- ResourceRPC *rpc.ClientConfig
- MemberRPC *rpc.ClientConfig
- LocationRPC *rpc.ClientConfig
- // db
- MySQL *MySQL
- // ecode
- // ecode
- Ecode *ecode.Config
- // redis
- Redis *Redis
- // mc
- Memcache *Memcache
- // search
- Search *Search
- // space
- Space *Space
- // contribute
- ContributePub *databus.Config
- CoinClient *warden.ClientConfig
- // BroadcastRPC grpc
- PGCRPC *warden.ClientConfig
- // build limit
- SearchBuildLimit *SearchBuildLimit
- // login build
- LoginBuild *LoginBuild
- // infoc
- Infoc *infoc.Config
- // fav Client
- FavClient *warden.ClientConfig
- // search dynamic
- SearchDynamicSwitch *SearchDynamicSwitch
- }
- // LoginBuild is
- type LoginBuild struct {
- Iphone int
- }
- // HTTPServers Http Servers
- type HTTPServers struct {
- Outer *bm.ServerConfig
- }
- // Host struct
- type Host struct {
- Account string
- Bangumi string
- APICo string
- Im9 string
- Search string
- Game string
- Space string
- Elec string
- VC string
- APILiveCo string
- WWW string
- Show string
- Pay string
- Member string
- Mall string
- }
- // MySQL struct
- type MySQL struct {
- Show *sql.Config
- }
- // Redis struct
- type Redis struct {
- Contribute *struct {
- *redis.Config
- Expire xtime.Duration
- }
- }
- // Memcache struct
- type Memcache struct {
- Archive *struct {
- *memcache.Config
- RecommedExpire xtime.Duration
- ArchiveExpire xtime.Duration
- }
- }
- // Search struct
- type Search struct {
- SeasonNum int
- MovieNum int
- SeasonMore int
- MovieMore int
- UpUserNum int
- UVLimit int
- UserNum int
- UserVideoLimit int
- BiliUserNum int
- BiliUserVideoLimit int
- OperationNum int
- IPadSearchBangumi int
- IPadSearchFt int
- }
- // Space struct
- type Space struct {
- ForbidMid []int64
- }
- // SearchBuildLimit struct
- type SearchBuildLimit struct {
- PGCHighLightIOS int
- PGCHighLightAndroid int
- PGCALLIOS int
- PGCALLAndroid int
- SpecialerGuideIOS int
- SpecialerGuideAndroid int
- SearchArticleIOS int
- SearchArticleAndroid int
- ComicIOS int
- ComicAndroid int
- ChannelIOS int
- ChannelAndroid int
- CooperationIOS int
- CooperationAndroid int
- QueryCorIOS int
- QueryCorAndroid int
- SugDetailIOS int
- SugDetailAndroid int
- NewTwitterIOS int
- NewTwitterAndroid int
- }
- type SearchDynamicSwitch struct {
- IsUP bool
- IsCount bool
- }
- 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
- }
- client.Watch("app-interface.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
- }
|