Easily handle JSON and environment based config in one go.
// Define your projects configuration.
//
// Validation is handled by https://github.com/go-playground/validator
type OurConfig struct {
FromJSON string `json:"from_json" validate:"required"`
FromEnv string `env:"FROM_ENV" validate:"required"`
}
// Specify where to find your projects configuration files.
var cfg OurConfig
err := config.NewFromFile(&config.Config{
Path: "./config",
Environment: config.Local,
}, &cfg)
// If there were no validation errors cfg will now be populated with values from
// the local JSON file as well as the environment.
More examples can be found here.
go-env
For marshalling from the environment.
validator
For validation.