https://github.com/osspkg/go-config
https://github.com/osspkg/go-config
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/osspkg/go-config
- Owner: osspkg
- License: bsd-3-clause
- Created: 2024-07-28T21:58:14.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-08-25T12:50:36.000Z (over 1 year ago)
- Last Synced: 2024-08-25T13:52:35.457Z (over 1 year ago)
- Language: Go
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Config Resolver
Updating the config through resolver variables.
## Config example
update config via ENV
```text
@env(key#defaut value)
```
```yaml
envs:
home: "@env(HOME#/tmp/home)"
path: "@env(PATH#/usr/local/bin)"
```
```go
import (
"go.osspkg.com/config"
"go.osspkg.com/config/env"
)
type (
ConfigItem struct {
Home string `yaml:"home"`
Path string `yaml:"path"`
}
Config struct {
Envs testConfigItem `yaml:"envs"`
}
)
func main() {
conf := Config{}
res := config.NewConfigResolve(
env.New(), // env resolver
)
res.OpenFile("./config.yaml") // open config file
res.Build() // prepare config with resolvers
res.Decode(&conf) // decoding config
fmt.Println(conf.Envs.Home)
fmt.Println(conf.Envs.Path)
}
```