@@ -83,6 +83,8 @@ func init() {
83
83
func newApp () * application {
84
84
return & application {
85
85
opt : & options {},
86
+ cltCfg : newClientConfig (),
87
+ svrCfg : newServerConfig (),
86
88
tarsConfig : make (map [string ]* transport.TarsServerConf ),
87
89
goSvrs : make (map [string ]* transport.TarsServer ),
88
90
httpSvrs : make (map [string ]* http.Server ),
@@ -123,8 +125,6 @@ func (a *application) initConfig() {
123
125
})
124
126
}()
125
127
}()
126
- a .svrCfg = newServerConfig ()
127
- a .cltCfg = newClientConfig ()
128
128
if ServerConfigPath == "" {
129
129
svrFlag := flag .NewFlagSet (os .Args [0 ], flag .ContinueOnError )
130
130
svrFlag .StringVar (& ServerConfigPath , "config" , "" , "server config path" )
@@ -140,9 +140,32 @@ func (a *application) initConfig() {
140
140
TLOG .Errorf ("Parse server config fail %v" , err )
141
141
return
142
142
}
143
+
144
+ // parse config
145
+ a .parseServerConfig (c )
146
+ a .parseClientConfig (c )
143
147
a .conf = c
144
148
145
- // Config.go
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 ) {
146
169
// init server config
147
170
if strings .EqualFold (c .GetString ("/tars/application<enableset>" ), "Y" ) {
148
171
a .svrCfg .Enableset = true
@@ -173,24 +196,6 @@ func (a *application) initConfig() {
173
196
// add adapters config
174
197
a .svrCfg .Adapters = make (map [string ]adapterConfig )
175
198
176
- cachePath := filepath .Join (a .svrCfg .DataPath , a .svrCfg .Server ) + ".tarsdat"
177
- if cacheData , err := os .ReadFile (cachePath ); err == nil {
178
- _ = json .Unmarshal (cacheData , & a .appCache )
179
- }
180
-
181
- if a .svrCfg .LogLevel == "" {
182
- a .svrCfg .LogLevel = a .appCache .LogLevel
183
- } else {
184
- a .appCache .LogLevel = a .svrCfg .LogLevel
185
- }
186
- rogger .SetLevel (rogger .StringToLevel (a .svrCfg .LogLevel ))
187
- if a .svrCfg .LogPath != "" {
188
- _ = TLOG .SetFileRoller (a .svrCfg .LogPath + "/" + a .svrCfg .App + "/" + a .svrCfg .Server , int (a .svrCfg .LogNum ), int (a .svrCfg .LogSize ))
189
- }
190
-
191
- // cache
192
- a .appCache .TarsVersion = Version
193
-
194
199
// add timeout config
195
200
a .svrCfg .AcceptTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/server<accepttimeout>" , AcceptTimeout ))
196
201
a .svrCfg .ReadTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/server<readtimeout>" , ReadTimeout ))
@@ -214,11 +219,14 @@ func (a *application) initConfig() {
214
219
a .svrCfg .StatReportChannelBufLen = c .GetInt32WithDef ("/tars/application/server<statreportchannelbuflen>" , StatReportChannelBufLen )
215
220
// maxPackageLength
216
221
a .svrCfg .MaxPackageLength = c .GetIntWithDef ("/tars/application/server<maxPackageLength>" , MaxPackageLength )
217
- protocol . SetMaxPackageLength ( a . svrCfg . MaxPackageLength )
222
+
218
223
// tls
219
224
a .svrCfg .Key = c .GetString ("/tars/application/server<key>" )
220
225
a .svrCfg .Cert = c .GetString ("/tars/application/server<cert>" )
221
- var tlsConfig * tls.Config
226
+ var (
227
+ tlsConfig * tls.Config
228
+ err error
229
+ )
222
230
if a .svrCfg .Key != "" && a .svrCfg .Cert != "" {
223
231
a .svrCfg .CA = c .GetString ("/tars/application/server<ca>" )
224
232
a .svrCfg .VerifyClient = c .GetStringWithDef ("/tars/application/server<verifyclient>" , "0" ) != "0"
@@ -233,39 +241,6 @@ func (a *application) initConfig() {
233
241
a .svrCfg .SampleAddress = c .GetString ("/tars/application/server<sampleaddress>" )
234
242
a .svrCfg .SampleEncoding = c .GetStringWithDef ("/tars/application/server<sampleencoding>" , "json" )
235
243
236
- // init client config
237
- cMap := c .GetMap ("/tars/application/client" )
238
- a .cltCfg .Locator = cMap ["locator" ]
239
- a .cltCfg .Stat = cMap ["stat" ]
240
- a .cltCfg .Property = cMap ["property" ]
241
- a .cltCfg .ModuleName = cMap ["modulename" ]
242
- a .cltCfg .AsyncInvokeTimeout = c .GetIntWithDef ("/tars/application/client<async-invoke-timeout>" , AsyncInvokeTimeout )
243
- a .cltCfg .RefreshEndpointInterval = c .GetIntWithDef ("/tars/application/client<refresh-endpoint-interval>" , refreshEndpointInterval )
244
- a .cltCfg .ReportInterval = c .GetIntWithDef ("/tars/application/client<report-interval>" , reportInterval )
245
- a .cltCfg .CheckStatusInterval = c .GetIntWithDef ("/tars/application/client<check-status-interval>" , checkStatusInterval )
246
- a .cltCfg .KeepAliveInterval = c .GetIntWithDef ("/tars/application/client<keep-alive-interval>" , keepAliveInterval )
247
-
248
- // add client timeout
249
- a .cltCfg .ClientQueueLen = c .GetIntWithDef ("/tars/application/client<clientqueuelen>" , ClientQueueLen )
250
- a .cltCfg .ClientIdleTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/client<clientidletimeout>" , ClientIdleTimeout ))
251
- a .cltCfg .ClientReadTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/client<clientreadtimeout>" , ClientReadTimeout ))
252
- a .cltCfg .ClientWriteTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/client<clientwritetimeout>" , ClientWriteTimeout ))
253
- a .cltCfg .ClientDialTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/client<clientdialtimeout>" , ClientDialTimeout ))
254
- a .cltCfg .ReqDefaultTimeout = c .GetInt32WithDef ("/tars/application/client<reqdefaulttimeout>" , ReqDefaultTimeout )
255
- a .cltCfg .ObjQueueMax = c .GetInt32WithDef ("/tars/application/client<objqueuemax>" , ObjQueueMax )
256
- a .cltCfg .context ["node_name" ] = a .svrCfg .NodeName
257
- ca := c .GetString ("/tars/application/client<ca>" )
258
- if ca != "" {
259
- cert := c .GetString ("/tars/application/client<cert>" )
260
- key := c .GetString ("/tars/application/client<key>" )
261
- ciphers := c .GetString ("/tars/application/client<ciphers>" )
262
- clientTlsConfig , err := ssl .NewClientTlsConfig (ca , cert , key , ciphers )
263
- if err != nil {
264
- panic (err )
265
- }
266
- a .clientTlsConfig = clientTlsConfig
267
- }
268
-
269
244
serList := c .GetDomain ("/tars/application/server" )
270
245
for _ , adapter := range serList {
271
246
endString := c .GetString ("/tars/application/server/" + adapter + "<endpoint>" )
@@ -285,7 +260,7 @@ func (a *application) initConfig() {
285
260
key := c .GetString ("/tars/application/server/" + adapter + "<key>" )
286
261
cert := c .GetString ("/tars/application/server/" + adapter + "<cert>" )
287
262
if key != "" && cert != "" {
288
- ca = c .GetString ("/tars/application/server/" + adapter + "<ca>" )
263
+ ca : = c .GetString ("/tars/application/server/" + adapter + "<ca>" )
289
264
verifyClient := c .GetString ("/tars/application/server/" + adapter + "<verifyclient>" ) != "0"
290
265
ciphers := c .GetString ("/tars/application/server/" + adapter + "<ciphers>" )
291
266
var adpTlsConfig * tls.Config
@@ -303,8 +278,6 @@ func (a *application) initConfig() {
303
278
}
304
279
a .serList = serList
305
280
306
- TLOG .Debug ("config add " , a .tarsConfig )
307
-
308
281
if len (a .svrCfg .Local ) > 0 {
309
282
localPoint := endpoint .Parse (a .svrCfg .Local )
310
283
// 管理端口不启动协程池
@@ -313,6 +286,43 @@ func (a *application) initConfig() {
313
286
RegisterAdmin (rogger .Admin , rogger .HandleDyeingAdmin )
314
287
}
315
288
289
+ TLOG .Debug ("config add " , a .tarsConfig )
290
+ }
291
+
292
+ func (a * application ) parseClientConfig (c * conf.Conf ) {
293
+ // init client config
294
+ cMap := c .GetMap ("/tars/application/client" )
295
+ a .cltCfg .Locator = cMap ["locator" ]
296
+ a .cltCfg .Stat = cMap ["stat" ]
297
+ a .cltCfg .Property = cMap ["property" ]
298
+ a .cltCfg .ModuleName = cMap ["modulename" ]
299
+ a .cltCfg .AsyncInvokeTimeout = c .GetIntWithDef ("/tars/application/client<async-invoke-timeout>" , AsyncInvokeTimeout )
300
+ a .cltCfg .RefreshEndpointInterval = c .GetIntWithDef ("/tars/application/client<refresh-endpoint-interval>" , refreshEndpointInterval )
301
+ a .cltCfg .ReportInterval = c .GetIntWithDef ("/tars/application/client<report-interval>" , reportInterval )
302
+ a .cltCfg .CheckStatusInterval = c .GetIntWithDef ("/tars/application/client<check-status-interval>" , checkStatusInterval )
303
+ a .cltCfg .KeepAliveInterval = c .GetIntWithDef ("/tars/application/client<keep-alive-interval>" , keepAliveInterval )
304
+
305
+ // add client timeout
306
+ a .cltCfg .ClientQueueLen = c .GetIntWithDef ("/tars/application/client<clientqueuelen>" , ClientQueueLen )
307
+ a .cltCfg .ClientIdleTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/client<clientidletimeout>" , ClientIdleTimeout ))
308
+ a .cltCfg .ClientReadTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/client<clientreadtimeout>" , ClientReadTimeout ))
309
+ a .cltCfg .ClientWriteTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/client<clientwritetimeout>" , ClientWriteTimeout ))
310
+ a .cltCfg .ClientDialTimeout = tools .ParseTimeOut (c .GetIntWithDef ("/tars/application/client<clientdialtimeout>" , ClientDialTimeout ))
311
+ a .cltCfg .ReqDefaultTimeout = c .GetInt32WithDef ("/tars/application/client<reqdefaulttimeout>" , ReqDefaultTimeout )
312
+ a .cltCfg .ObjQueueMax = c .GetInt32WithDef ("/tars/application/client<objqueuemax>" , ObjQueueMax )
313
+ a .cltCfg .context ["node_name" ] = a .svrCfg .NodeName
314
+ ca := c .GetString ("/tars/application/client<ca>" )
315
+ if ca != "" {
316
+ cert := c .GetString ("/tars/application/client<cert>" )
317
+ key := c .GetString ("/tars/application/client<key>" )
318
+ ciphers := c .GetString ("/tars/application/client<ciphers>" )
319
+ clientTlsConfig , err := ssl .NewClientTlsConfig (ca , cert , key , ciphers )
320
+ if err != nil {
321
+ panic (err )
322
+ }
323
+ a .clientTlsConfig = clientTlsConfig
324
+ }
325
+
316
326
auths := c .GetDomain ("/tars/application/client" )
317
327
for _ , objName := range auths {
318
328
authInfo := make (map [string ]string )
@@ -324,15 +334,13 @@ func (a *application) initConfig() {
324
334
authInfo ["ciphers" ] = c .GetString ("/tars/application/client/" + objName + "<ciphers>" )
325
335
a .clientObjInfo [objName ] = authInfo
326
336
if authInfo ["ca" ] != "" {
327
- var objTlsConfig * tls.Config
328
- objTlsConfig , err = ssl .NewClientTlsConfig (authInfo ["ca" ], authInfo ["cert" ], authInfo ["key" ], authInfo ["ciphers" ])
337
+ objTlsConfig , err := ssl .NewClientTlsConfig (authInfo ["ca" ], authInfo ["cert" ], authInfo ["key" ], authInfo ["ciphers" ])
329
338
if err != nil {
330
339
panic (err )
331
340
}
332
341
a .clientObjTlsConfig [objName ] = objTlsConfig
333
342
}
334
343
}
335
- _ , _ = maxprocs .Set (maxprocs .Logger (TLOG .Infof ))
336
344
}
337
345
338
346
// Run the application
0 commit comments