Skip to content

be-true/config-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Config system for go lang apps

Example of usage

  • 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 |

About

Config system for go lang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages