Tiny package to populate your structs from environment variables.
Install it:
go get github.com/dmytro-vovk/envsetImport it:
import "github.com/dmytro-vovk/envset"Use it:
- Define your structure, e.g:
type MyConfig struct {
Webserver struct {
Listen string `env:"LISTEN" default:":8080"`
}
Logfile string `env:"LOG_FILE"`
}- Create a variable of your type:
var config &MyConfig - Call the package to populate the variable:
if err := envset.Set(&config); err != nil {
log.Fatalf("Error setting config from environment: %s", err)
}- Set environment variables and run your app:
LISTEN="localhost:8088" LOG_FILE="/tmp/my_app.log" go run main.go