rookie-ninja / rk-boot

Build microservice with rk-boot and let the team take over clean and tidy code.
https://rkdev.info
Apache License 2.0
514 stars 59 forks source link

config replace by env has bug when key contain dot #155

Open careyyoung opened 4 months ago

careyyoung commented 4 months ago

Describe the bug 依赖版本: github.com/rookie-ninja/rk-boot/v2 v2.2.22 github.com/rookie-ninja/rk-cache/redis v1.2.17 github.com/rookie-ninja/rk-db/mongodb v1.2.18 github.com/rookie-ninja/rk-db/redis v1.2.18 github.com/rookie-ninja/rk-entry/v2 v2.2.22 github.com/rookie-ninja/rk-gin/v2 v2.2.23 现象:

  1. 使用了配置文件:
  2. 获取配置:rkentry.GlobalAppCtx.GetConfigEntry("config").GetBool("key1.enable")
  3. 如果使用环境变量:key1_enable,覆盖不了配置文件中的值,
  4. 需要使用key1.enable,才能覆盖
  5. 应该是:github.com\rookie-ninja\rk-entry\v2@v2.2.22\entry\configentry.go 该行:entry.Viper.AutomaticEnv() 前 缺少调用:entry.Viper.SetEnvKeyReplacer(strings.NewReplacer(".", ""))

期望结果: 使用环境变量:key1_enable,可以覆盖配置文件中的值

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.