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.
MIT License
2.56k stars 146 forks source link

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

Closed dengliu closed 2 weeks ago

dengliu commented 2 months ago

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

Additional context Add any other context about the problem here.

rhnvrm commented 2 months ago

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: https://github.com/knadh/koanf/blob/7e52f5219bf02926169bacb637f109aea793fe47/tests/fs_test.go#L92