Simple config golang library to load `k=v` from config files, environment variables and command line flags
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lunny Xiao b306ffe445
Support time.Duration
2 months ago
.circleci fix tests 2 years ago
.drone.yml fix bug blank when load flags or envs 1 year ago
.gitignore Support time.Duration 2 months ago
LICENSE fix lints 1 year ago
README.md Add LoadIfExist (#1) 8 months ago
README_CN.md update README 1 year ago
config.go Support time.Duration 2 months ago
config_test.go Support time.Duration 2 months ago
doc.go fix doc 8 months ago
error.go fix lints 1 year ago
go.mod fix bug blank when load flags or envs 1 year ago
go.sum fix bug blank when load flags or envs 1 year ago
load.go fix flags parse 8 months ago
load_test.go Add LoadIfExist (#1) 8 months ago
test_cfg.ini Support time.Duration 2 months ago

README.md

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