fix #794
Showing
1 changed file
with
187 additions
and
146 deletions
| ... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
| 15 | package beego | 15 | package beego |
| 16 | 16 | ||
| 17 | import ( | 17 | import ( |
| 18 | "errors" | ||
| 19 | "fmt" | 18 | "fmt" |
| 20 | "html/template" | 19 | "html/template" |
| 21 | "os" | 20 | "os" |
| ... | @@ -48,8 +47,8 @@ var ( | ... | @@ -48,8 +47,8 @@ var ( |
| 48 | RecoverPanic bool // flag of auto recover panic | 47 | RecoverPanic bool // flag of auto recover panic |
| 49 | AutoRender bool // flag of render template automatically | 48 | AutoRender bool // flag of render template automatically |
| 50 | ViewsPath string | 49 | ViewsPath string |
| 50 | AppConfig *beegoAppConfig | ||
| 51 | RunMode string // run mode, "dev" or "prod" | 51 | RunMode string // run mode, "dev" or "prod" |
| 52 | AppConfig config.ConfigContainer | ||
| 53 | GlobalSessions *session.Manager // global session mananger | 52 | GlobalSessions *session.Manager // global session mananger |
| 54 | SessionOn bool // flag of starting session auto. default is false. | 53 | SessionOn bool // flag of starting session auto. default is false. |
| 55 | SessionProvider string // default session provider, memory, mysql , redis ,etc. | 54 | SessionProvider string // default session provider, memory, mysql , redis ,etc. |
| ... | @@ -84,6 +83,107 @@ var ( | ... | @@ -84,6 +83,107 @@ var ( |
| 84 | RouterCaseSensitive bool // router case sensitive default is true | 83 | RouterCaseSensitive bool // router case sensitive default is true |
| 85 | ) | 84 | ) |
| 86 | 85 | ||
| 86 | type beegoAppConfig struct { | ||
| 87 | innerConfig config.ConfigContainer | ||
| 88 | } | ||
| 89 | |||
| 90 | func newAppConfig(AppConfigProvider, AppConfigPath string) *beegoAppConfig { | ||
| 91 | ac, err := config.NewConfig(AppConfigProvider, AppConfigPath) | ||
| 92 | if err != nil { | ||
| 93 | ac = config.NewFakeConfig() | ||
| 94 | } | ||
| 95 | rac := &beegoAppConfig{ac} | ||
| 96 | return rac | ||
| 97 | } | ||
| 98 | |||
| 99 | func (b *beegoAppConfig) Set(key, val string) error { | ||
| 100 | return b.innerConfig.Set(key, val) | ||
| 101 | } | ||
| 102 | |||
| 103 | func (b *beegoAppConfig) String(key string) string { | ||
| 104 | v := b.innerConfig.String(RunMode + "::" + key) | ||
| 105 | if v == "" { | ||
| 106 | return b.innerConfig.String(key) | ||
| 107 | } | ||
| 108 | return v | ||
| 109 | } | ||
| 110 | |||
| 111 | func (b *beegoAppConfig) Strings(key string) []string { | ||
| 112 | v := b.innerConfig.Strings(RunMode + "::" + key) | ||
| 113 | if len(v) == 0 { | ||
| 114 | return b.innerConfig.Strings(key) | ||
| 115 | } | ||
| 116 | return v | ||
| 117 | } | ||
| 118 | |||
| 119 | func (b *beegoAppConfig) Int(key string) (int, error) { | ||
| 120 | v, err := b.innerConfig.Int(RunMode + "::" + key) | ||
| 121 | if err != nil { | ||
| 122 | return b.innerConfig.Int(key) | ||
| 123 | } | ||
| 124 | return v, nil | ||
| 125 | } | ||
| 126 | |||
| 127 | func (b *beegoAppConfig) Int64(key string) (int64, error) { | ||
| 128 | v, err := b.innerConfig.Int64(RunMode + "::" + key) | ||
| 129 | if err != nil { | ||
| 130 | return b.innerConfig.Int64(key) | ||
| 131 | } | ||
| 132 | return v, nil | ||
| 133 | } | ||
| 134 | |||
| 135 | func (b *beegoAppConfig) Bool(key string) (bool, error) { | ||
| 136 | v, err := b.innerConfig.Bool(RunMode + "::" + key) | ||
| 137 | if err != nil { | ||
| 138 | return b.innerConfig.Bool(key) | ||
| 139 | } | ||
| 140 | return v, nil | ||
| 141 | } | ||
| 142 | |||
| 143 | func (b *beegoAppConfig) Float(key string) (float64, error) { | ||
| 144 | v, err := b.innerConfig.Float(RunMode + "::" + key) | ||
| 145 | if err != nil { | ||
| 146 | return b.innerConfig.Float(key) | ||
| 147 | } | ||
| 148 | return v, nil | ||
| 149 | } | ||
| 150 | |||
| 151 | func (b *beegoAppConfig) DefaultString(key string, defaultval string) string { | ||
| 152 | return b.innerConfig.DefaultString(key, defaultval) | ||
| 153 | } | ||
| 154 | |||
| 155 | func (b *beegoAppConfig) DefaultStrings(key string, defaultval []string) []string { | ||
| 156 | return b.innerConfig.DefaultStrings(key, defaultval) | ||
| 157 | } | ||
| 158 | |||
| 159 | func (b *beegoAppConfig) DefaultInt(key string, defaultval int) int { | ||
| 160 | return b.innerConfig.DefaultInt(key, defaultval) | ||
| 161 | } | ||
| 162 | |||
| 163 | func (b *beegoAppConfig) DefaultInt64(key string, defaultval int64) int64 { | ||
| 164 | return b.innerConfig.DefaultInt64(key, defaultval) | ||
| 165 | } | ||
| 166 | |||
| 167 | func (b *beegoAppConfig) DefaultBool(key string, defaultval bool) bool { | ||
| 168 | return b.innerConfig.DefaultBool(key, defaultval) | ||
| 169 | } | ||
| 170 | |||
| 171 | func (b *beegoAppConfig) DefaultFloat(key string, defaultval float64) float64 { | ||
| 172 | return b.innerConfig.DefaultFloat(key, defaultval) | ||
| 173 | } | ||
| 174 | |||
| 175 | func (b *beegoAppConfig) DIY(key string) (interface{}, error) { | ||
| 176 | return b.innerConfig.DIY(key) | ||
| 177 | } | ||
| 178 | |||
| 179 | func (b *beegoAppConfig) GetSection(section string) (map[string]string, error) { | ||
| 180 | return b.innerConfig.GetSection(section) | ||
| 181 | } | ||
| 182 | |||
| 183 | func (b *beegoAppConfig) SaveConfigFile(filename string) error { | ||
| 184 | return b.innerConfig.SaveConfigFile(filename) | ||
| 185 | } | ||
| 186 | |||
| 87 | func init() { | 187 | func init() { |
| 88 | // create beego application | 188 | // create beego application |
| 89 | BeeApp = NewApp() | 189 | BeeApp = NewApp() |
| ... | @@ -186,157 +286,152 @@ func init() { | ... | @@ -186,157 +286,152 @@ func init() { |
| 186 | // ParseConfig parsed default config file. | 286 | // ParseConfig parsed default config file. |
| 187 | // now only support ini, next will support json. | 287 | // now only support ini, next will support json. |
| 188 | func ParseConfig() (err error) { | 288 | func ParseConfig() (err error) { |
| 189 | AppConfig, err = config.NewConfig(AppConfigProvider, AppConfigPath) | 289 | AppConfig = newAppConfig(AppConfigProvider, AppConfigPath) |
| 190 | if err != nil { | ||
| 191 | AppConfig = config.NewFakeConfig() | ||
| 192 | return err | ||
| 193 | } else { | ||
| 194 | 290 | ||
| 195 | if v, err := GetConfig("string", "HttpAddr"); err == nil { | 291 | // set the runmode first |
| 196 | HttpAddr = v.(string) | 292 | if runmode := AppConfig.String("RunMode"); runmode != "" { |
| 293 | RunMode = runmode | ||
| 197 | } | 294 | } |
| 198 | 295 | ||
| 199 | if v, err := GetConfig("int", "HttpPort"); err == nil { | 296 | HttpAddr = AppConfig.String("HttpAddr") |
| 200 | HttpPort = v.(int) | ||
| 201 | } | ||
| 202 | 297 | ||
| 203 | if v, err := GetConfig("bool", "EnableHttpListen"); err == nil { | 298 | if v, err := AppConfig.Int("HttpPort"); err == nil { |
| 204 | EnableHttpListen = v.(bool) | 299 | HttpPort = v |
| 205 | } | 300 | } |
| 206 | 301 | ||
| 207 | if maxmemory, err := GetConfig("int64", "MaxMemory"); err == nil { | 302 | if v, err := AppConfig.Bool("EnableHttpListen"); err == nil { |
| 208 | MaxMemory = maxmemory.(int64) | 303 | EnableHttpListen = v |
| 209 | } | 304 | } |
| 210 | 305 | ||
| 211 | if appname, _ := GetConfig("string", "AppName"); appname != "" { | 306 | if maxmemory, err := AppConfig.Int64("MaxMemory"); err == nil { |
| 212 | AppName = appname.(string) | 307 | MaxMemory = maxmemory |
| 213 | } | 308 | } |
| 214 | 309 | ||
| 215 | if runmode, _ := GetConfig("string", "RunMode"); runmode != "" { | 310 | if appname := AppConfig.String("AppName"); appname != "" { |
| 216 | RunMode = runmode.(string) | 311 | AppName = appname |
| 217 | } | 312 | } |
| 218 | 313 | ||
| 219 | if autorender, err := GetConfig("bool", "AutoRender"); err == nil { | 314 | if autorender, err := AppConfig.Bool("AutoRender"); err == nil { |
| 220 | AutoRender = autorender.(bool) | 315 | AutoRender = autorender |
| 221 | } | 316 | } |
| 222 | 317 | ||
| 223 | if autorecover, err := GetConfig("bool", "RecoverPanic"); err == nil { | 318 | if autorecover, err := AppConfig.Bool("RecoverPanic"); err == nil { |
| 224 | RecoverPanic = autorecover.(bool) | 319 | RecoverPanic = autorecover |
| 225 | } | 320 | } |
| 226 | 321 | ||
| 227 | if views, _ := GetConfig("string", "ViewsPath"); views != "" { | 322 | if views := AppConfig.String("ViewsPath"); views != "" { |
| 228 | ViewsPath = views.(string) | 323 | ViewsPath = views |
| 229 | } | 324 | } |
| 230 | 325 | ||
| 231 | if sessionon, err := GetConfig("bool", "SessionOn"); err == nil { | 326 | if sessionon, err := AppConfig.Bool("SessionOn"); err == nil { |
| 232 | SessionOn = sessionon.(bool) | 327 | SessionOn = sessionon |
| 233 | } | 328 | } |
| 234 | 329 | ||
| 235 | if sessProvider, _ := GetConfig("string", "SessionProvider"); sessProvider != "" { | 330 | if sessProvider := AppConfig.String("SessionProvider"); sessProvider != "" { |
| 236 | SessionProvider = sessProvider.(string) | 331 | SessionProvider = sessProvider |
| 237 | } | 332 | } |
| 238 | 333 | ||
| 239 | if sessName, _ := GetConfig("string", "SessionName"); sessName != "" { | 334 | if sessName := AppConfig.String("SessionName"); sessName != "" { |
| 240 | SessionName = sessName.(string) | 335 | SessionName = sessName |
| 241 | } | 336 | } |
| 242 | 337 | ||
| 243 | if sesssavepath, _ := GetConfig("string", "SessionSavePath"); sesssavepath != "" { | 338 | if sesssavepath := AppConfig.String("SessionSavePath"); sesssavepath != "" { |
| 244 | SessionSavePath = sesssavepath.(string) | 339 | SessionSavePath = sesssavepath |
| 245 | } | 340 | } |
| 246 | 341 | ||
| 247 | if sesshashfunc, _ := GetConfig("string", "SessionHashFunc"); sesshashfunc != "" { | 342 | if sesshashfunc := AppConfig.String("SessionHashFunc"); sesshashfunc != "" { |
| 248 | SessionHashFunc = sesshashfunc.(string) | 343 | SessionHashFunc = sesshashfunc |
| 249 | } | 344 | } |
| 250 | 345 | ||
| 251 | if sesshashkey, _ := GetConfig("string", "SessionHashKey"); sesshashkey != "" { | 346 | if sesshashkey := AppConfig.String("SessionHashKey"); sesshashkey != "" { |
| 252 | SessionHashKey = sesshashkey.(string) | 347 | SessionHashKey = sesshashkey |
| 253 | } | 348 | } |
| 254 | 349 | ||
| 255 | if sessMaxLifeTime, err := GetConfig("int64", "SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 { | 350 | if sessMaxLifeTime, err := AppConfig.Int64("SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 { |
| 256 | SessionGCMaxLifetime = sessMaxLifeTime.(int64) | 351 | SessionGCMaxLifetime = sessMaxLifeTime |
| 257 | } | 352 | } |
| 258 | 353 | ||
| 259 | if sesscookielifetime, err := GetConfig("int", "SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 { | 354 | if sesscookielifetime, err := AppConfig.Int("SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 { |
| 260 | SessionCookieLifeTime = sesscookielifetime.(int) | 355 | SessionCookieLifeTime = sesscookielifetime |
| 261 | } | 356 | } |
| 262 | 357 | ||
| 263 | if usefcgi, err := GetConfig("bool", "UseFcgi"); err == nil { | 358 | if usefcgi, err := AppConfig.Bool("UseFcgi"); err == nil { |
| 264 | UseFcgi = usefcgi.(bool) | 359 | UseFcgi = usefcgi |
| 265 | } | 360 | } |
| 266 | 361 | ||
| 267 | if enablegzip, err := GetConfig("bool", "EnableGzip"); err == nil { | 362 | if enablegzip, err := AppConfig.Bool("EnableGzip"); err == nil { |
| 268 | EnableGzip = enablegzip.(bool) | 363 | EnableGzip = enablegzip |
| 269 | } | 364 | } |
| 270 | 365 | ||
| 271 | if directoryindex, err := GetConfig("bool", "DirectoryIndex"); err == nil { | 366 | if directoryindex, err := AppConfig.Bool("DirectoryIndex"); err == nil { |
| 272 | DirectoryIndex = directoryindex.(bool) | 367 | DirectoryIndex = directoryindex |
| 273 | } | 368 | } |
| 274 | 369 | ||
| 275 | if timeout, err := GetConfig("int64", "HttpServerTimeOut"); err == nil { | 370 | if timeout, err := AppConfig.Int64("HttpServerTimeOut"); err == nil { |
| 276 | HttpServerTimeOut = timeout.(int64) | 371 | HttpServerTimeOut = timeout |
| 277 | } | 372 | } |
| 278 | 373 | ||
| 279 | if errorsshow, err := GetConfig("bool", "ErrorsShow"); err == nil { | 374 | if errorsshow, err := AppConfig.Bool("ErrorsShow"); err == nil { |
| 280 | ErrorsShow = errorsshow.(bool) | 375 | ErrorsShow = errorsshow |
| 281 | } | 376 | } |
| 282 | 377 | ||
| 283 | if copyrequestbody, err := GetConfig("bool", "CopyRequestBody"); err == nil { | 378 | if copyrequestbody, err := AppConfig.Bool("CopyRequestBody"); err == nil { |
| 284 | CopyRequestBody = copyrequestbody.(bool) | 379 | CopyRequestBody = copyrequestbody |
| 285 | } | 380 | } |
| 286 | 381 | ||
| 287 | if xsrfkey, _ := GetConfig("string", "XSRFKEY"); xsrfkey != "" { | 382 | if xsrfkey := AppConfig.String("XSRFKEY"); xsrfkey != "" { |
| 288 | XSRFKEY = xsrfkey.(string) | 383 | XSRFKEY = xsrfkey |
| 289 | } | 384 | } |
| 290 | 385 | ||
| 291 | if enablexsrf, err := GetConfig("bool", "EnableXSRF"); err == nil { | 386 | if enablexsrf, err := AppConfig.Bool("EnableXSRF"); err == nil { |
| 292 | EnableXSRF = enablexsrf.(bool) | 387 | EnableXSRF = enablexsrf |
| 293 | } | 388 | } |
| 294 | 389 | ||
| 295 | if expire, err := GetConfig("int", "XSRFExpire"); err == nil { | 390 | if expire, err := AppConfig.Int("XSRFExpire"); err == nil { |
| 296 | XSRFExpire = expire.(int) | 391 | XSRFExpire = expire |
| 297 | } | 392 | } |
| 298 | 393 | ||
| 299 | if tplleft, _ := GetConfig("string", "TemplateLeft"); tplleft != "" { | 394 | if tplleft := AppConfig.String("TemplateLeft"); tplleft != "" { |
| 300 | TemplateLeft = tplleft.(string) | 395 | TemplateLeft = tplleft |
| 301 | } | 396 | } |
| 302 | 397 | ||
| 303 | if tplright, _ := GetConfig("string", "TemplateRight"); tplright != "" { | 398 | if tplright := AppConfig.String("TemplateRight"); tplright != "" { |
| 304 | TemplateRight = tplright.(string) | 399 | TemplateRight = tplright |
| 305 | } | 400 | } |
| 306 | 401 | ||
| 307 | if httptls, err := GetConfig("bool", "EnableHttpTLS"); err == nil { | 402 | if httptls, err := AppConfig.Bool("EnableHttpTLS"); err == nil { |
| 308 | EnableHttpTLS = httptls.(bool) | 403 | EnableHttpTLS = httptls |
| 309 | } | 404 | } |
| 310 | 405 | ||
| 311 | if httpsport, err := GetConfig("int", "HttpsPort"); err == nil { | 406 | if httpsport, err := AppConfig.Int("HttpsPort"); err == nil { |
| 312 | HttpsPort = httpsport.(int) | 407 | HttpsPort = httpsport |
| 313 | } | 408 | } |
| 314 | 409 | ||
| 315 | if certfile, _ := GetConfig("string", "HttpCertFile"); certfile != "" { | 410 | if certfile := AppConfig.String("HttpCertFile"); certfile != "" { |
| 316 | HttpCertFile = certfile.(string) | 411 | HttpCertFile = certfile |
| 317 | } | 412 | } |
| 318 | 413 | ||
| 319 | if keyfile, _ := GetConfig("string", "HttpKeyFile"); keyfile != "" { | 414 | if keyfile := AppConfig.String("HttpKeyFile"); keyfile != "" { |
| 320 | HttpKeyFile = keyfile.(string) | 415 | HttpKeyFile = keyfile |
| 321 | } | 416 | } |
| 322 | 417 | ||
| 323 | if serverName, _ := GetConfig("string", "BeegoServerName"); serverName != "" { | 418 | if serverName := AppConfig.String("BeegoServerName"); serverName != "" { |
| 324 | BeegoServerName = serverName.(string) | 419 | BeegoServerName = serverName |
| 325 | } | 420 | } |
| 326 | 421 | ||
| 327 | if flashname, _ := GetConfig("string", "FlashName"); flashname != "" { | 422 | if flashname := AppConfig.String("FlashName"); flashname != "" { |
| 328 | FlashName = flashname.(string) | 423 | FlashName = flashname |
| 329 | } | 424 | } |
| 330 | 425 | ||
| 331 | if flashseperator, _ := GetConfig("string", "FlashSeperator"); flashseperator != "" { | 426 | if flashseperator := AppConfig.String("FlashSeperator"); flashseperator != "" { |
| 332 | FlashSeperator = flashseperator.(string) | 427 | FlashSeperator = flashseperator |
| 333 | } | 428 | } |
| 334 | 429 | ||
| 335 | if sd, _ := GetConfig("string", "StaticDir"); sd != "" { | 430 | if sd := AppConfig.String("StaticDir"); sd != "" { |
| 336 | for k := range StaticDir { | 431 | for k := range StaticDir { |
| 337 | delete(StaticDir, k) | 432 | delete(StaticDir, k) |
| 338 | } | 433 | } |
| 339 | sds := strings.Fields(sd.(string)) | 434 | sds := strings.Fields(sd) |
| 340 | for _, v := range sds { | 435 | for _, v := range sds { |
| 341 | if url2fsmap := strings.SplitN(v, ":", 2); len(url2fsmap) == 2 { | 436 | if url2fsmap := strings.SplitN(v, ":", 2); len(url2fsmap) == 2 { |
| 342 | StaticDir["/"+strings.TrimRight(url2fsmap[0], "/")] = url2fsmap[1] | 437 | StaticDir["/"+strings.TrimRight(url2fsmap[0], "/")] = url2fsmap[1] |
| ... | @@ -346,8 +441,8 @@ func ParseConfig() (err error) { | ... | @@ -346,8 +441,8 @@ func ParseConfig() (err error) { |
| 346 | } | 441 | } |
| 347 | } | 442 | } |
| 348 | 443 | ||
| 349 | if sgz, _ := GetConfig("string", "StaticExtensionsToGzip"); sgz != "" { | 444 | if sgz := AppConfig.String("StaticExtensionsToGzip"); sgz != "" { |
| 350 | extensions := strings.Split(sgz.(string), ",") | 445 | extensions := strings.Split(sgz, ",") |
| 351 | if len(extensions) > 0 { | 446 | if len(extensions) > 0 { |
| 352 | StaticExtensionsToGzip = []string{} | 447 | StaticExtensionsToGzip = []string{} |
| 353 | for _, ext := range extensions { | 448 | for _, ext := range extensions { |
| ... | @@ -363,78 +458,24 @@ func ParseConfig() (err error) { | ... | @@ -363,78 +458,24 @@ func ParseConfig() (err error) { |
| 363 | } | 458 | } |
| 364 | } | 459 | } |
| 365 | 460 | ||
| 366 | if enableadmin, err := GetConfig("bool", "EnableAdmin"); err == nil { | 461 | if enableadmin, err := AppConfig.Bool("EnableAdmin"); err == nil { |
| 367 | EnableAdmin = enableadmin.(bool) | 462 | EnableAdmin = enableadmin |
| 368 | } | 463 | } |
| 369 | 464 | ||
| 370 | if adminhttpaddr, _ := GetConfig("string", "AdminHttpAddr"); adminhttpaddr != "" { | 465 | if adminhttpaddr := AppConfig.String("AdminHttpAddr"); adminhttpaddr != "" { |
| 371 | AdminHttpAddr = adminhttpaddr.(string) | 466 | AdminHttpAddr = adminhttpaddr |
| 372 | } | 467 | } |
| 373 | 468 | ||
| 374 | if adminhttpport, err := GetConfig("int", "AdminHttpPort"); err == nil { | 469 | if adminhttpport, err := AppConfig.Int("AdminHttpPort"); err == nil { |
| 375 | AdminHttpPort = adminhttpport.(int) | 470 | AdminHttpPort = adminhttpport |
| 376 | } | 471 | } |
| 377 | 472 | ||
| 378 | if enabledocs, err := GetConfig("bool", "EnableDocs"); err == nil { | 473 | if enabledocs, err := AppConfig.Bool("EnableDocs"); err == nil { |
| 379 | EnableDocs = enabledocs.(bool) | 474 | EnableDocs = enabledocs |
| 380 | } | 475 | } |
| 381 | 476 | ||
| 382 | if casesensitive, err := GetConfig("bool", "RouterCaseSensitive"); err == nil { | 477 | if casesensitive, err := AppConfig.Bool("RouterCaseSensitive"); err == nil { |
| 383 | RouterCaseSensitive = casesensitive.(bool) | 478 | RouterCaseSensitive = casesensitive |
| 384 | } | ||
| 385 | } | 479 | } |
| 386 | return nil | 480 | return nil |
| 387 | } | 481 | } |
| 388 | |||
| 389 | // Getconfig throw the Runmode | ||
| 390 | // [dev] | ||
| 391 | // name = astaixe | ||
| 392 | // IsEnable = false | ||
| 393 | // [prod] | ||
| 394 | // name = slene | ||
| 395 | // IsEnable = true | ||
| 396 | // | ||
| 397 | // usage: | ||
| 398 | // GetConfig("string", "name") | ||
| 399 | // GetConfig("bool", "IsEnable") | ||
| 400 | func GetConfig(typ, key string) (interface{}, error) { | ||
| 401 | switch typ { | ||
| 402 | case "string": | ||
| 403 | v := AppConfig.String(RunMode + "::" + key) | ||
| 404 | if v == "" { | ||
| 405 | v = AppConfig.String(key) | ||
| 406 | } | ||
| 407 | return v, nil | ||
| 408 | case "strings": | ||
| 409 | v := AppConfig.Strings(RunMode + "::" + key) | ||
| 410 | if len(v) == 0 { | ||
| 411 | v = AppConfig.Strings(key) | ||
| 412 | } | ||
| 413 | return v, nil | ||
| 414 | case "int": | ||
| 415 | v, err := AppConfig.Int(RunMode + "::" + key) | ||
| 416 | if err != nil || v == 0 { | ||
| 417 | return AppConfig.Int(key) | ||
| 418 | } | ||
| 419 | return v, nil | ||
| 420 | case "bool": | ||
| 421 | v, err := AppConfig.Bool(RunMode + "::" + key) | ||
| 422 | if err != nil { | ||
| 423 | return AppConfig.Bool(key) | ||
| 424 | } | ||
| 425 | return v, nil | ||
| 426 | case "int64": | ||
| 427 | v, err := AppConfig.Int64(RunMode + "::" + key) | ||
| 428 | if err != nil || v == 0 { | ||
| 429 | return AppConfig.Int64(key) | ||
| 430 | } | ||
| 431 | return v, nil | ||
| 432 | case "float": | ||
| 433 | v, err := AppConfig.Float(RunMode + "::" + key) | ||
| 434 | if err != nil || v == 0 { | ||
| 435 | return AppConfig.Float(key) | ||
| 436 | } | ||
| 437 | return v, nil | ||
| 438 | } | ||
| 439 | return "", errors.New("not support type") | ||
| 440 | } | ... | ... |
-
Please register or sign in to post a comment