knadh / koanf

Simple, extremely lightweight, extensible, configuration management library for Go. Support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert non-string type to string in StringMap()

dengliu opened this issue · comments

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.

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"))