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

Can not parse environment variable

rts-gordon opened this issue · comments

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.

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_" ^