Skip to content

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

@careyyoung

Description

@careyyoung

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\config_entry.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):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions