MCPcopy
hub / github.com/TarsCloud/TarsGo / initConfig

Method initConfig

tars/application.go:120–166  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

118}
119
120func (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
168func (a *application) parseServerConfig(c *conf.Conf) {
169 // init server config

Callers 1

initMethod · 0.95

Calls 12

parseServerConfigMethod · 0.95
parseClientConfigMethod · 0.95
NewConfFunction · 0.92
SetLevelFunction · 0.92
StringToLevelFunction · 0.92
SetMaxPackageLengthFunction · 0.92
initReportFunction · 0.85
DoMethod · 0.80
SetFileRollerMethod · 0.80
SetMethod · 0.65
LoggerMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected