GetConfigResolver get config resolver
(conf *loaderConf)
| 369 | |
| 370 | // GetConfigResolver get config resolver |
| 371 | func GetConfigResolver(conf *loaderConf) *koanf.Koanf { |
| 372 | var ( |
| 373 | k *koanf.Koanf |
| 374 | err error |
| 375 | ) |
| 376 | if len(conf.suffix) <= 0 { |
| 377 | conf.suffix = string(file.YAML) |
| 378 | } |
| 379 | if len(conf.delim) <= 0 { |
| 380 | conf.delim = "." |
| 381 | } |
| 382 | bytes := conf.bytes |
| 383 | if len(bytes) <= 0 { |
| 384 | panic(errors.New("bytes is nil,please set bytes or file path")) |
| 385 | } |
| 386 | k = koanf.New(conf.delim) |
| 387 | |
| 388 | switch conf.suffix { |
| 389 | case "yaml", "yml": |
| 390 | err = k.Load(rawbytes.Provider(bytes), yaml.Parser()) |
| 391 | case "json": |
| 392 | err = k.Load(rawbytes.Provider(bytes), json.Parser()) |
| 393 | default: |
| 394 | err = errors.Errorf("no support %s file suffix", conf.suffix) |
| 395 | } |
| 396 | |
| 397 | if err != nil { |
| 398 | panic(err) |
| 399 | } |
| 400 | return resolvePlaceholder(k) |
| 401 | } |
| 402 | |
| 403 | // resolvePlaceholder replace ${xx} with real value |
| 404 | func resolvePlaceholder(resolver *koanf.Koanf) *koanf.Koanf { |
no test coverage detected