- Notifications
You must be signed in to change notification settings - Fork0
The safest Go package for parsing env vars
License
orsinium-labs/configenv
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Go package for parsing env vars.
The main idea is to enforce (on the package API design level) the best practice of parsing env vars: prevent duplicate names, wrong types, typos, etc. SeeWriting safe-to-use Go libraries on the design principles behind my Go packages, including this one.
Also, try outcliff, a package for safely parsing CLI args.
go get github.com/orsinium-labs/configenv
Given the following parser:
typeConfigstruct {DebugboolEnvstring}config:=Config{}vars:= configenv.Vars{"DEBUG":configenv.Required(configenv.Bool(&config.Debug)),"ENV":configenv.String(&config.Env),}err:=vars.Parse(configenv.Config{Prefix:"BE_"})
And the following env vars:
export BE_DEBUG=trueexport BE_ENV=prod
You will getConfig{Debug: true, Env: "prod"}
If you instead ofBE_DEBUG=true provideDEBUG=true,BE_DEUG=true, orBE_DEBUG=maybe, the parser will detect it and return an error.
About
The safest Go package for parsing env vars
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.