Simple config golang library to load k=v from config files, environment variables and command line flags
Go to file
Lunny Xiao b306ffe445
All checks were successful
continuous-integration/drone/push Build is passing
Support time.Duration
2020-05-01 11:46:37 +08:00
.circleci fix tests 2018-03-29 14:39:21 +08:00
.drone.yml fix bug blank when load flags or envs 2019-05-21 14:29:02 +08:00
.gitignore Support time.Duration 2020-05-01 11:46:37 +08:00
config_test.go Support time.Duration 2020-05-01 11:46:37 +08:00
config.go Support time.Duration 2020-05-01 11:46:37 +08:00
doc.go fix doc 2019-10-29 13:15:43 +08:00
error.go fix lints 2019-03-11 17:01:08 +08:00
go.mod fix bug blank when load flags or envs 2019-05-21 14:29:02 +08:00
go.sum fix bug blank when load flags or envs 2019-05-21 14:29:02 +08:00
LICENSE fix lints 2019-03-11 17:01:08 +08:00
load_test.go Add LoadIfExist (#1) 2019-10-29 05:08:14 +00:00
load.go fix flags parse 2019-11-01 09:51:50 +08:00
README_CN.md update README 2019-05-21 14:34:22 +08:00
README.md Add LoadIfExist (#1) 2019-10-29 05:08:14 +00:00
test_cfg.ini Support time.Duration 2020-05-01 11:46:37 +08:00

config

Build Status GoDoc

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())