https://github.com/ActiveState/doozerconfig
Go package for managing json-encoded configuration in Doozer
https://github.com/ActiveState/doozerconfig
Last synced: about 1 year ago
JSON representation
Go package for managing json-encoded configuration in Doozer
- Host: GitHub
- URL: https://github.com/ActiveState/doozerconfig
- Owner: ActiveState
- License: other
- Created: 2012-09-26T17:47:02.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2013-03-11T03:50:08.000Z (over 13 years ago)
- Last Synced: 2024-08-03T15:05:57.304Z (almost 2 years ago)
- Language: Go
- Size: 131 KB
- Stars: 2
- Watchers: 54
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# doozerconfig
## What Is It?
doozerconfig is a Go package for managing json-encoded configuration in doozer. Configuration in doozer is directly mapped to a Go struct. Configuration changes made in doozer are automatically reflected in the struct. For details, see the example below.
[API documentation](http://godoc.org/github.com/ActiveState/doozerconfig)
## Installation
```bash
$ go get github.com/ActiveState/doozerconfig
```
## Example
```Go
var Config struct {
MaxItems int `doozer:"config/max_items"`
DbUri string `doozer:"config/db_uri"`
EnvVars map[string]string `doozer:"config/envvars"`
Verbose bool // not in doozer
}
func init() {
doozer, _ := doozer.Dial("localhost:8046")
rev, _ := doozer.Rev()
// Map Config fields to "/myapp/" + the struct tag above.
// eg: MaxItems will be mapped to /myapp/config/max_items
// EnvVars will be mapped to /myapp/config/envvars/*
cfg := doozerconfig.New(doozer, rev, &Config, "/myapp/")
// Load config values from doozer and assign to Config fields
_ = cfg.Load()
// Watch for live changes to doozer config, and automatically
// update the struct fields. The callback function can be used to
// handle errors, and to get notified of changes.
go cfg.Monitor("/myapp/config/*", func(change *Change, err error) {
fmt.Printf("config changed in doozer; %+v\n", change)
})
}
```
# Notes
- If a file is deleted from doozer, the config struct is not updated
(unless it a map entry). Perhaps we should update the value to a
default value (as specified in a `default` struct tag).
- Writing configuration back to doozer is not supported yet.
# Changes
- **Oct 22, 2012**:
- Support for loading map types
- API: `Load` now takes doozer revision as a mandatory argument.
- API: `Monitor` doesn't take a revision argument anymore. Instead
it uses the one passed to `Load`.
- API: `Monitor`'s callback function accepts a new `Change` struct.
- **Sep 25, 2012**:
- Initial public release.