An open API service indexing awesome lists of open source software.

https://github.com/osspkg/go-config


https://github.com/osspkg/go-config

Last synced: about 1 year ago
JSON representation

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

```