This is an automated archive.
The original was posted on /r/golang by /u/RedoubtableBeast on 2023-09-03 07:05:23+00:00.
Hi folks!
Let me introduce tiny pet project
Why systemd-styled env files? It is well known, well documented and widespread format. It allows comments, spaces around =
, blank lines, multiline values... You cat check out main features at this playground
It is two in one: library and CLI tool.
The CLI tool works as expected. Just like that:
xenv you_script arg arg arg
You can customize looking up env-files using XENV=PATH:PATH:PATH eviroment.
The library provides two functions (details and example at pkg.go.dev): low-level parser and high-level helper.
If you are loading you configuration in that way:
env := os.Environ()
cfg := Load(env)
You are free to let it consider env file like that:
env, err := sdenv.Environ(os.Environ(), "config.env") // you are free to specify several files
if err != nil {
panic(err)
}
cfg := Load(env)
This library and CLI have TODOs, however they are not vital. I hope to find more ideas here. You are welcome to open issues or just drop you thoughts right here.