3d74a1a4 by astaxie

make the getconfig public

// Getconfig throw the Runmode
// [dev]
// name = astaixe
// IsEnable = false
// [prod]
// name = slene
// IsEnable = true
//
// usage:
// GetConfig("string", "name")
// GetConfig("bool", "IsEnable")
1 parent 00eac0e4
Showing 1 changed file with 53 additions and 42 deletions
...@@ -184,147 +184,147 @@ func ParseConfig() (err error) { ...@@ -184,147 +184,147 @@ func ParseConfig() (err error) {
184 return err 184 return err
185 } else { 185 } else {
186 186
187 if v, err := getConfig("string", "HttpAddr"); err == nil { 187 if v, err := GetConfig("string", "HttpAddr"); err == nil {
188 HttpAddr = v.(string) 188 HttpAddr = v.(string)
189 } 189 }
190 190
191 if v, err := getConfig("int", "HttpPort"); err == nil { 191 if v, err := GetConfig("int", "HttpPort"); err == nil {
192 HttpPort = v.(int) 192 HttpPort = v.(int)
193 } 193 }
194 194
195 if v, err := getConfig("bool", "EnableHttpListen"); err == nil { 195 if v, err := GetConfig("bool", "EnableHttpListen"); err == nil {
196 EnableHttpListen = v.(bool) 196 EnableHttpListen = v.(bool)
197 } 197 }
198 198
199 if maxmemory, err := getConfig("int64", "MaxMemory"); err == nil { 199 if maxmemory, err := GetConfig("int64", "MaxMemory"); err == nil {
200 MaxMemory = maxmemory.(int64) 200 MaxMemory = maxmemory.(int64)
201 } 201 }
202 202
203 if appname, _ := getConfig("string", "AppName"); appname != "" { 203 if appname, _ := GetConfig("string", "AppName"); appname != "" {
204 AppName = appname.(string) 204 AppName = appname.(string)
205 } 205 }
206 206
207 if runmode, _ := getConfig("string", "RunMode"); runmode != "" { 207 if runmode, _ := GetConfig("string", "RunMode"); runmode != "" {
208 RunMode = runmode.(string) 208 RunMode = runmode.(string)
209 } 209 }
210 210
211 if autorender, err := getConfig("bool", "AutoRender"); err == nil { 211 if autorender, err := GetConfig("bool", "AutoRender"); err == nil {
212 AutoRender = autorender.(bool) 212 AutoRender = autorender.(bool)
213 } 213 }
214 214
215 if autorecover, err := getConfig("bool", "RecoverPanic"); err == nil { 215 if autorecover, err := GetConfig("bool", "RecoverPanic"); err == nil {
216 RecoverPanic = autorecover.(bool) 216 RecoverPanic = autorecover.(bool)
217 } 217 }
218 218
219 if views, _ := getConfig("string", "ViewsPath"); views != "" { 219 if views, _ := GetConfig("string", "ViewsPath"); views != "" {
220 ViewsPath = views.(string) 220 ViewsPath = views.(string)
221 } 221 }
222 222
223 if sessionon, err := getConfig("bool", "SessionOn"); err == nil { 223 if sessionon, err := GetConfig("bool", "SessionOn"); err == nil {
224 SessionOn = sessionon.(bool) 224 SessionOn = sessionon.(bool)
225 } 225 }
226 226
227 if sessProvider, _ := getConfig("string", "SessionProvider"); sessProvider != "" { 227 if sessProvider, _ := GetConfig("string", "SessionProvider"); sessProvider != "" {
228 SessionProvider = sessProvider.(string) 228 SessionProvider = sessProvider.(string)
229 } 229 }
230 230
231 if sessName, _ := getConfig("string", "SessionName"); sessName != "" { 231 if sessName, _ := GetConfig("string", "SessionName"); sessName != "" {
232 SessionName = sessName.(string) 232 SessionName = sessName.(string)
233 } 233 }
234 234
235 if sesssavepath, _ := getConfig("string", "SessionSavePath"); sesssavepath != "" { 235 if sesssavepath, _ := GetConfig("string", "SessionSavePath"); sesssavepath != "" {
236 SessionSavePath = sesssavepath.(string) 236 SessionSavePath = sesssavepath.(string)
237 } 237 }
238 238
239 if sesshashfunc, _ := getConfig("string", "SessionHashFunc"); sesshashfunc != "" { 239 if sesshashfunc, _ := GetConfig("string", "SessionHashFunc"); sesshashfunc != "" {
240 SessionHashFunc = sesshashfunc.(string) 240 SessionHashFunc = sesshashfunc.(string)
241 } 241 }
242 242
243 if sesshashkey, _ := getConfig("string", "SessionHashKey"); sesshashkey != "" { 243 if sesshashkey, _ := GetConfig("string", "SessionHashKey"); sesshashkey != "" {
244 SessionHashKey = sesshashkey.(string) 244 SessionHashKey = sesshashkey.(string)
245 } 245 }
246 246
247 if sessMaxLifeTime, err := getConfig("int64", "SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 { 247 if sessMaxLifeTime, err := GetConfig("int64", "SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 {
248 SessionGCMaxLifetime = sessMaxLifeTime.(int64) 248 SessionGCMaxLifetime = sessMaxLifeTime.(int64)
249 } 249 }
250 250
251 if sesscookielifetime, err := getConfig("int", "SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 { 251 if sesscookielifetime, err := GetConfig("int", "SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 {
252 SessionCookieLifeTime = sesscookielifetime.(int) 252 SessionCookieLifeTime = sesscookielifetime.(int)
253 } 253 }
254 254
255 if usefcgi, err := getConfig("bool", "UseFcgi"); err == nil { 255 if usefcgi, err := GetConfig("bool", "UseFcgi"); err == nil {
256 UseFcgi = usefcgi.(bool) 256 UseFcgi = usefcgi.(bool)
257 } 257 }
258 258
259 if enablegzip, err := getConfig("bool", "EnableGzip"); err == nil { 259 if enablegzip, err := GetConfig("bool", "EnableGzip"); err == nil {
260 EnableGzip = enablegzip.(bool) 260 EnableGzip = enablegzip.(bool)
261 } 261 }
262 262
263 if directoryindex, err := getConfig("bool", "DirectoryIndex"); err == nil { 263 if directoryindex, err := GetConfig("bool", "DirectoryIndex"); err == nil {
264 DirectoryIndex = directoryindex.(bool) 264 DirectoryIndex = directoryindex.(bool)
265 } 265 }
266 266
267 if timeout, err := getConfig("int64", "HttpServerTimeOut"); err == nil { 267 if timeout, err := GetConfig("int64", "HttpServerTimeOut"); err == nil {
268 HttpServerTimeOut = timeout.(int64) 268 HttpServerTimeOut = timeout.(int64)
269 } 269 }
270 270
271 if errorsshow, err := getConfig("bool", "ErrorsShow"); err == nil { 271 if errorsshow, err := GetConfig("bool", "ErrorsShow"); err == nil {
272 ErrorsShow = errorsshow.(bool) 272 ErrorsShow = errorsshow.(bool)
273 } 273 }
274 274
275 if copyrequestbody, err := getConfig("bool", "CopyRequestBody"); err == nil { 275 if copyrequestbody, err := GetConfig("bool", "CopyRequestBody"); err == nil {
276 CopyRequestBody = copyrequestbody.(bool) 276 CopyRequestBody = copyrequestbody.(bool)
277 } 277 }
278 278
279 if xsrfkey, _ := getConfig("string", "XSRFKEY"); xsrfkey != "" { 279 if xsrfkey, _ := GetConfig("string", "XSRFKEY"); xsrfkey != "" {
280 XSRFKEY = xsrfkey.(string) 280 XSRFKEY = xsrfkey.(string)
281 } 281 }
282 282
283 if enablexsrf, err := getConfig("bool", "EnableXSRF"); err == nil { 283 if enablexsrf, err := GetConfig("bool", "EnableXSRF"); err == nil {
284 EnableXSRF = enablexsrf.(bool) 284 EnableXSRF = enablexsrf.(bool)
285 } 285 }
286 286
287 if expire, err := getConfig("int", "XSRFExpire"); err == nil { 287 if expire, err := GetConfig("int", "XSRFExpire"); err == nil {
288 XSRFExpire = expire.(int) 288 XSRFExpire = expire.(int)
289 } 289 }
290 290
291 if tplleft, _ := getConfig("string", "TemplateLeft"); tplleft != "" { 291 if tplleft, _ := GetConfig("string", "TemplateLeft"); tplleft != "" {
292 TemplateLeft = tplleft.(string) 292 TemplateLeft = tplleft.(string)
293 } 293 }
294 294
295 if tplright, _ := getConfig("string", "TemplateRight"); tplright != "" { 295 if tplright, _ := GetConfig("string", "TemplateRight"); tplright != "" {
296 TemplateRight = tplright.(string) 296 TemplateRight = tplright.(string)
297 } 297 }
298 298
299 if httptls, err := getConfig("bool", "EnableHttpTLS"); err == nil { 299 if httptls, err := GetConfig("bool", "EnableHttpTLS"); err == nil {
300 EnableHttpTLS = httptls.(bool) 300 EnableHttpTLS = httptls.(bool)
301 } 301 }
302 302
303 if httpsport, err := getConfig("int", "HttpsPort"); err == nil { 303 if httpsport, err := GetConfig("int", "HttpsPort"); err == nil {
304 HttpsPort = httpsport.(int) 304 HttpsPort = httpsport.(int)
305 } 305 }
306 306
307 if certfile, _ := getConfig("string", "HttpCertFile"); certfile != "" { 307 if certfile, _ := GetConfig("string", "HttpCertFile"); certfile != "" {
308 HttpCertFile = certfile.(string) 308 HttpCertFile = certfile.(string)
309 } 309 }
310 310
311 if keyfile, _ := getConfig("string", "HttpKeyFile"); keyfile != "" { 311 if keyfile, _ := GetConfig("string", "HttpKeyFile"); keyfile != "" {
312 HttpKeyFile = keyfile.(string) 312 HttpKeyFile = keyfile.(string)
313 } 313 }
314 314
315 if serverName, _ := getConfig("string", "BeegoServerName"); serverName != "" { 315 if serverName, _ := GetConfig("string", "BeegoServerName"); serverName != "" {
316 BeegoServerName = serverName.(string) 316 BeegoServerName = serverName.(string)
317 } 317 }
318 318
319 if flashname, _ := getConfig("string", "FlashName"); flashname != "" { 319 if flashname, _ := GetConfig("string", "FlashName"); flashname != "" {
320 FlashName = flashname.(string) 320 FlashName = flashname.(string)
321 } 321 }
322 322
323 if flashseperator, _ := getConfig("string", "FlashSeperator"); flashseperator != "" { 323 if flashseperator, _ := GetConfig("string", "FlashSeperator"); flashseperator != "" {
324 FlashSeperator = flashseperator.(string) 324 FlashSeperator = flashseperator.(string)
325 } 325 }
326 326
327 if sd, _ := getConfig("string", "StaticDir"); sd != "" { 327 if sd, _ := GetConfig("string", "StaticDir"); sd != "" {
328 for k := range StaticDir { 328 for k := range StaticDir {
329 delete(StaticDir, k) 329 delete(StaticDir, k)
330 } 330 }
...@@ -338,7 +338,7 @@ func ParseConfig() (err error) { ...@@ -338,7 +338,7 @@ func ParseConfig() (err error) {
338 } 338 }
339 } 339 }
340 340
341 if sgz, _ := getConfig("string", "StaticExtensionsToGzip"); sgz != "" { 341 if sgz, _ := GetConfig("string", "StaticExtensionsToGzip"); sgz != "" {
342 extensions := strings.Split(sgz.(string), ",") 342 extensions := strings.Split(sgz.(string), ",")
343 if len(extensions) > 0 { 343 if len(extensions) > 0 {
344 StaticExtensionsToGzip = []string{} 344 StaticExtensionsToGzip = []string{}
...@@ -355,26 +355,37 @@ func ParseConfig() (err error) { ...@@ -355,26 +355,37 @@ func ParseConfig() (err error) {
355 } 355 }
356 } 356 }
357 357
358 if enableadmin, err := getConfig("bool", "EnableAdmin"); err == nil { 358 if enableadmin, err := GetConfig("bool", "EnableAdmin"); err == nil {
359 EnableAdmin = enableadmin.(bool) 359 EnableAdmin = enableadmin.(bool)
360 } 360 }
361 361
362 if adminhttpaddr, _ := getConfig("string", "AdminHttpAddr"); adminhttpaddr != "" { 362 if adminhttpaddr, _ := GetConfig("string", "AdminHttpAddr"); adminhttpaddr != "" {
363 AdminHttpAddr = adminhttpaddr.(string) 363 AdminHttpAddr = adminhttpaddr.(string)
364 } 364 }
365 365
366 if adminhttpport, err := getConfig("int", "AdminHttpPort"); err == nil { 366 if adminhttpport, err := GetConfig("int", "AdminHttpPort"); err == nil {
367 AdminHttpPort = adminhttpport.(int) 367 AdminHttpPort = adminhttpport.(int)
368 } 368 }
369 369
370 if enabledocs, err := getConfig("bool", "EnableDocs"); err == nil { 370 if enabledocs, err := GetConfig("bool", "EnableDocs"); err == nil {
371 EnableDocs = enabledocs.(bool) 371 EnableDocs = enabledocs.(bool)
372 } 372 }
373 } 373 }
374 return nil 374 return nil
375 } 375 }
376 376
377 func getConfig(typ, key string) (interface{}, error) { 377 // Getconfig throw the Runmode
378 // [dev]
379 // name = astaixe
380 // IsEnable = false
381 // [prod]
382 // name = slene
383 // IsEnable = true
384 //
385 // usage:
386 // GetConfig("string", "name")
387 // GetConfig("bool", "IsEnable")
388 func GetConfig(typ, key string) (interface{}, error) {
378 switch typ { 389 switch typ {
379 case "string": 390 case "string":
380 v := AppConfig.String(RunMode + "::" + key) 391 v := AppConfig.String(RunMode + "::" + key)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!