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.71k stars 150 forks source link

Can not parse environment variable #258

Closed rts-gordon closed 9 months ago

rts-gordon commented 9 months ago

Hi there,

There are some environment variable defined like this:

[app]
env = "dev"
env.prefix = "TMT_"

the parse code:

    ENV = koanf.New(".")
    if err := ENV.Load(file.Provider(configFile), toml.Parser()); err != nil {
        log.Fatalf("error loading config file: %v", err)
    }

This will occurs error:

error loading config file: (8, 1): Unknown table type for path: app.env

But if the variable change like this, the parse will pass.

[app]
env.value = "dev"
env.prefix = "TMT_"

My question is: why the 'env' and 'env.prefix' confict? they are two different variables.

Thank you.

knadh commented 9 months ago

Hi. That's invalid TOML. You can paste the snippet and validate it here.

https://www.toml-lint.com/

Can't redefine existing key at row 3, col 20, pos 38: 2: env = "dev" 3> env.prefix = "TMT_" ^