- If you described config like below
type Config struct {
Env string `config:"enum=local|dev|qa|stage|prod"`
Port int `config:"format=port,default=3000"`
Hosts []string `config:"format=url,require,splitter=|,doc='You doc info'"`
Enabled bool `config:"format=boolean,default=true"`
}
- Than you call parsing envs variable to this config
conf := Config{}
setup := config.Setup{
suffix: "APPLICATION_",
}
err := config.FromEnv(&conf, setup)
In system has variables:
APPLICATION_ENV=prod
APPLICATION_PORT=3000
APPLICATION_HOSTS=domain1.com:5555|domain2.com:5555
APPLICATION_ENABLED=true
- Config should be equal:
Config{
Env: "prod",
Port: 3000,
Hosts: []{"domain1.com:5555", "domain2.com:5555"},
Enabled: true,
}
- If in config has errors, than you may call method for visualize errors in terminal
if err != nil {
log.Fatal(err)
}
- Errors will printed in terminal as md table
| error | env | format | doc | example |
|----------|-------------------|--------|--------------|------------------------------|
| required | APPLICATION_HOSTS | url | You doc info | domain1:port1\|domain2:port2 |