123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- 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"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/http/blademaster/middleware/antispam"
- "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"
- "go-common/library/time"
- "github.com/BurntSushi/toml"
- )
- var (
- Conf = &Config{}
- client *conf.Client
- confPath string
- )
- type Config struct {
-
-
- Host *Host
-
- Xlog *log.Config
-
- AuthN *auth.Config
-
- Verify *verify.Config
-
- BM *HTTPServers
-
- Mysql *sql.Config
-
- Memcache *Memcache
-
- Redis *Redis
-
- DataBus *databus.Config
-
- Tracer *trace.Config
-
- HTTPClient *bm.ClientConfig
-
- Judge *Judge
-
- Ecode *ecode.Config
-
- Antispam *antispam.Config
-
- TagID *TagID
-
- Property *Property
-
- RPCClient2 *RPC
-
- GRPCClient *GRPC
- }
- type Redis struct {
- *redis.Config
- Expire time.Duration
- }
- type Memcache struct {
- *memcache.Config
- UserExpire time.Duration
- MinCommonExpire time.Duration
- CommonExpire time.Duration
- }
- type Host struct {
- MessageURI string
- BigDataURI string
- APICoURI string
- ManagersURI string
- }
- type Judge struct {
- ConfTimer time.Duration
- ReservedTime time.Duration
- LoadManagerTime time.Duration
- CaseGiveHours int64
- CaseCheckTime int64
- JuryRatio int64
- JudgeRadio int64
- CaseVoteMin int64
- CaseObtainMax int64
- CaseVoteMax int64
- JuryApplyMax int64
- CaseLoadMax int
- CaseLoadSwitch int8
- VoteNum
- }
- type VoteNum struct {
- RateS int8 `json:"rate_s"`
- RateA int8 `json:"rate_a"`
- RateB int8 `json:"rate_b"`
- RateC int8 `json:"rate_c"`
- RateD int8 `json:"rate_d"`
- }
- type RPC struct {
- Archive *rpc.ClientConfig
- Member *rpc.ClientConfig
- }
- type GRPC struct {
- Filter *warden.ClientConfig
- Account *warden.ClientConfig
- }
- type HTTPServers struct {
- Inner *bm.ServerConfig
- Local *bm.ServerConfig
- }
- type TagID struct {
- Reply int64
- DM int64
- Msg int64
- Tag int64
- Member int64
- Archive int64
- Music int64
- Article int64
- SpaceTop int64
- }
- type Property struct {
- QsNum int
- PerScore int64
- }
- func init() {
- flag.StringVar(&confPath, "conf", "", "default config path")
- }
- func Init() (err 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
- }
|