https://github.com/dmotylev/appconfig
Golang library for gathering configuration data from different sources
https://github.com/dmotylev/appconfig
12-factor appconfig configuration go
Last synced: 9 months ago
JSON representation
Golang library for gathering configuration data from different sources
- Host: GitHub
- URL: https://github.com/dmotylev/appconfig
- Owner: dmotylev
- License: mit
- Created: 2013-12-08T22:10:41.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-03-17T09:13:00.000Z (about 9 years ago)
- Last Synced: 2024-06-20T05:12:08.118Z (almost 2 years ago)
- Topics: 12-factor, appconfig, configuration, go
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 13
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AppConfig [](https://travis-ci.org/dmotylev/appconfig) [](https://coveralls.io/r/dmotylev/appconfig) [](https://goreportcard.com/report/github.com/dmotylev/appconfig) [](https://godoc.org/github.com/dmotylev/appconfig)
```Go
import "github.com/dmotylev/appconfig"
```
## Documentation
See [GoDoc](http://godoc.org/github.com/dmotylev/appconfig).
## Usage
Set environment variables:
```Bash
APP_TIMEOUT=1h2m3s
APP_WORKERNAME=Monkey
```
Write other values to the file:
```Bash
cat > local.conf << EOF
APP_TIMEOUT=2h2m3s
APP_NUMWORKERS=10
APP_WORKERNAME=Robot
EOF
```
Write code:
Populate variable from both sources:
```Go
package main
import (
"fmt"
"time"
"github.com/dmotylev/appconfig"
)
func main() {
var conf struct {
Timeout time.Duration
Day time.Time `time,format:"2006-01-02"`
WorkerName string
NumWorkers int
}
err := appconfig.Load(&conf, appconfig.FromEnv("APP_"), appconfig.FromFile("local.conf"))
fmt.Printf("err=%v\n", err)
fmt.Printf("timeout=%s\n", conf.Timeout)
fmt.Printf("day=%s\n", conf.Day.Format(time.UnixDate))
fmt.Printf("worker=%s\n", conf.WorkerName)
fmt.Printf("workers=%d\n", conf.NumWorkers)
}
```
Results:
```Bash
err=
timeout=1h2m3s
day=Fri Dec 13 00:00:00 UTC 2013
worker=Monkey
workers=10
```
Get some inspiration from tests.
# License
The package available under [LICENSE](https://github.com/dmotylev/appconfig/blob/master/LICENSE).