|
||
---|---|---|
.circleci | ||
.drone.yml | ||
.gitignore | ||
config_test.go | ||
config.go | ||
doc.go | ||
error.go | ||
go.mod | ||
go.sum | ||
LICENSE | ||
load_test.go | ||
load.go | ||
README_CN.md | ||
README.md | ||
test_cfg.ini |
config
Config is a simple config package to load config items from files, command line flags and enviroment variables.
Installation
go get gitea.com/lunny/config
Example
The config format is simliar with ini but simpler(don't support sections), like below:
a=b
c=d
// load config items from file, envs or command line flags
cfgs, err := Load("config.ini")
if err != nil {
t.Error(err)
}
// if you want to ignore the error if file is not exist, then it will read envs or command line flags
cfgs, err := LoadIfExist("config.ini")
if err != nil {
t.Error(err)
}
Load config from flags:
cfgs := New(LoadFlags())
Load config from envs:
cfgs := New(LoadEnvs())