Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert non-string type to string in StringMap() #291

Open
dengliu opened this issue May 2, 2024 · 1 comment
Open

Convert non-string type to string in StringMap() #291

dengliu opened this issue May 2, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dengliu
Copy link

dengliu commented May 2, 2024

Describe the bug
A clear and concise description of what the bug is.
For a yaml object like this I expect StringMap() returns a map[string]string object like this below. However it returns an empty string without fmt.print the integer to a string
However, String() does fmt.print the integer to a string.

Does it make sense to make StringMap() consistent with String() ?
I can cut a PR for this.

{ "cpu_core_limit": "1", mem_limit:"50%", "concurrency_limit": "2"}

resourceLimit:
  cpu_core_limit: 1
  mem_limit: 50%
  concurrency_limit: 2

https://github.com/knadh/koanf/blob/master/getters.go#L458-L461

To Reproduce
Steps / breaking unit test / example to reproduce the behavior

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

Please provide the following information):

  • OS: osx
  • Koanf Version v2.1.1

Additional context
Add any other context about the problem here.

@dengliu dengliu added the bug Something isn't working label May 2, 2024
@rhnvrm
Copy link
Collaborator

rhnvrm commented May 10, 2024

Hi,

StringMap checks that the path sent to it is a StringMap (map[string]string). If it does not match that type, then we return an empty map.

Ref:

assert.Equal(map[string]string{}, c.koanf.StringMap("parent1.intmap"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants