| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package singlematch
- import (
- "encoding/json"
- "os"
- "time"
- "bet24.com/log"
- platformconfig "bet24.com/servers/micros/platformconfig/proto"
- )
- const config_key = "matches_singlematch"
- const refresh_config_sec = 1800
- var cfgmgr *configmgr
- func getConfigManager() *configmgr {
- if cfgmgr == nil {
- cfgmgr = new(configmgr)
- cfgmgr.ctor()
- }
- return cfgmgr
- }
- type configmgr struct {
- Matches []SingleMatchConfig
- configString string
- }
- func (cm *configmgr) ctor() {
- cm.loadConfig()
- }
- func (cm *configmgr) loadConfig() {
- time.AfterFunc(time.Second*600, cm.loadConfig)
- configString := platformconfig.GetConfig(config_key)
- if configString == "" {
- data, err := os.ReadFile("serviceconf/matches_singlematch.json")
- if err != nil {
- log.Release("configmgr.loadData read config failed")
- return
- }
- configString = string(data)
- if configString != "" {
- platformconfig.SetConfig(config_key, configString)
- }
- }
- if configString == cm.configString {
- return
- }
- cm.configString = configString
- // 读取配置
- err := json.Unmarshal([]byte(configString), &cm.Matches)
- if err != nil {
- log.Release("configmgr.loadData Unmarshal failed %s", configString)
- }
- // 设置Index
- for i := 0; i < len(cm.Matches); i++ {
- cm.Matches[i].createRoundIndex()
- }
- }
- func (cm *configmgr) dumpSys(param string) {
- log.Release("-------------------------------")
- log.Release("configmgr.dumpSys")
- defer func() {
- log.Release("+++++++++++++++++++++++++++++++")
- log.Release("")
- }()
- for _, v := range cm.Matches {
- log.Release("MatchId:%d", v.MatchId)
- v.dump()
- }
- }
- func (cm *configmgr) getMatch(matchId int) *SingleMatchConfig {
- for _, v := range cm.Matches {
- if v.MatchId == matchId {
- return &v
- }
- }
- return nil
- }
|