https://github.com/plimble/goconf
Go config library
https://github.com/plimble/goconf
config golang
Last synced: 7 months ago
JSON representation
Go config library
- Host: GitHub
- URL: https://github.com/plimble/goconf
- Owner: plimble
- License: mit
- Created: 2017-05-25T22:31:35.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-26T00:42:45.000Z (over 7 years ago)
- Last Synced: 2024-10-21T10:15:45.084Z (almost 2 years ago)
- Topics: config, golang
- Language: Go
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
goconf
---
[](https://godoc.org/github.com/plimble/goconf)
[](https://travis-ci.org/plimble/goconf?branch=master)
[](https://coveralls.io/github/plimble/goconf?branch=master)
[](https://goreportcard.com/report/plimble/goconf)
Combine yaml and environment config
## Features
- [Parse yaml](gopkg.in/yaml.v2)
- [Parse env](github.com/kelseyhightower/envconfig)
- Watch yaml config file
## Installation
```
go get gopkg.in/plimble/goconf.v1
```
## Env format
```go
type SampleA struct {
A string // PREFIX_A
CamelCase bool // PREFIX_CAMELCASE
ManualOverride1 string `envconfig:"manual_override_1"` // PREFIX_MANUAL_OVERRIDE_1
SplitWord1 string `split_words:"true"` // SPLIT_WORD1
ID string // PREFIX_ID
DefaultValue string `envconfig:"DEFAULT_VALUE"` // PREFIX_DEFAULT_VALUE
}
```
## Yaml format
```go
type SampleA struct {
A string `json:"abc"` // abc
CamelCase bool `yaml:"cc"` // cc
ManualOverride1 string // manualoverride1
SplitWord1 string // splitword1
ID string // id
DefaultValue string // defaultvalue
}
```
## Example
```go
type Sample struct {
Value string
}
var bytes = `
value: v1
`
sample := &Sample{}
// Parse Order: yaml bytes -> yaml file -> env
err = goconf.Parse(sample,
WithEnv("prefix"),
WithYamlFromBytes(bytes),
WithYaml("path.yml"),
)
```
## Watch Config
```go
goconf.WatchYamlFile("path.yml", sample, func() error {
fmt.Println("event on chane")
return nil
})
// or ignore event
goconf.WatchYamlFile("path.yml", sample, nil)
```