Skip to content

dmytro-vovk/envset

Repository files navigation

EnvSet

Tiny package to populate your structs from environment variables.

Usage

Install it:

go get github.com/dmytro-vovk/envset

Import it:

import "github.com/dmytro-vovk/envset"

Use it:

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages