()
| 118 | } |
| 119 | |
| 120 | func (a *application) initConfig() { |
| 121 | defer func() { |
| 122 | go func() { |
| 123 | _ = statInitOnce.Do(func() error { |
| 124 | return initReport(a) |
| 125 | }) |
| 126 | }() |
| 127 | }() |
| 128 | if ServerConfigPath == "" { |
| 129 | svrFlag := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) |
| 130 | svrFlag.StringVar(&ServerConfigPath, "config", "", "server config path") |
| 131 | _ = svrFlag.Parse(os.Args[1:]) |
| 132 | } |
| 133 | |
| 134 | if len(ServerConfigPath) == 0 { |
| 135 | return |
| 136 | } |
| 137 | |
| 138 | c, err := conf.NewConf(ServerConfigPath) |
| 139 | if err != nil { |
| 140 | TLOG.Errorf("Parse server config fail %v", err) |
| 141 | return |
| 142 | } |
| 143 | |
| 144 | // parse config |
| 145 | a.parseServerConfig(c) |
| 146 | a.parseClientConfig(c) |
| 147 | a.conf = c |
| 148 | |
| 149 | cachePath := filepath.Join(a.svrCfg.DataPath, a.svrCfg.Server) + ".tarsdat" |
| 150 | if cacheData, err := os.ReadFile(cachePath); err == nil { |
| 151 | _ = json.Unmarshal(cacheData, &a.appCache) |
| 152 | } |
| 153 | // cache |
| 154 | a.appCache.TarsVersion = Version |
| 155 | if a.svrCfg.LogLevel == "" { |
| 156 | a.svrCfg.LogLevel = a.appCache.LogLevel |
| 157 | } else { |
| 158 | a.appCache.LogLevel = a.svrCfg.LogLevel |
| 159 | } |
| 160 | rogger.SetLevel(rogger.StringToLevel(a.svrCfg.LogLevel)) |
| 161 | if a.svrCfg.LogPath != "" { |
| 162 | _ = TLOG.SetFileRoller(a.svrCfg.LogPath+"/"+a.svrCfg.App+"/"+a.svrCfg.Server, int(a.svrCfg.LogNum), int(a.svrCfg.LogSize)) |
| 163 | } |
| 164 | protocol.SetMaxPackageLength(a.svrCfg.MaxPackageLength) |
| 165 | _, _ = maxprocs.Set(maxprocs.Logger(TLOG.Infof)) |
| 166 | } |
| 167 | |
| 168 | func (a *application) parseServerConfig(c *conf.Conf) { |
| 169 | // init server config |
no test coverage detected