Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prodyna/goconfig
Library for loading configuration files (yaml, ...) into structs
https://github.com/prodyna/goconfig
Last synced: about 2 months ago
JSON representation
Library for loading configuration files (yaml, ...) into structs
- Host: GitHub
- URL: https://github.com/prodyna/goconfig
- Owner: PRODYNA
- License: mit
- Created: 2021-11-15T10:48:44.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-23T11:33:58.000Z (almost 2 years ago)
- Last Synced: 2023-07-27T22:29:23.851Z (over 1 year ago)
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goconfig
Library for loading configuration files (yaml, ...) into structs## Basic usage
Assuming you have a file called config.yaml in the default path
```yaml
name: Hello
```And a struct
```golang
type Configuration struct {
Name string `yaml:"name"`
}
```Load the yaml file into the struct
```golang
cfg := &Configuration{}
err := NewConfigLoader().LoadConfig( c)
name := cfg.Name
...
```## Basic usage with env variables
Assuming you have a file called config.yaml in the default path
and an exported environment variable MY_PWD = "secretvalue"```yaml
name: Hello
pwd: "{Env:MY_PWD}
```And a struct
```golang
type Configuration struct {
Name string `yaml:"name"`
Pwd string `yaml:"pwd"`
}
```Load the yaml file into the struct
```golang
cfg := &Configuration{}
err := NewConfigLoader().LoadConfig( c)
name := cfg.Name
pwd := cfg.Pwd
...
```### Different paths
The default paths for searching a config file are
```
"", "k8s/dev/", "config/", "./config/", "/config/"
```You can set the paths to new locations with:
```golang
cfg := &Configuration{}
err := NewConfigLoader().Paths("/mypath/").LoadConfig( c)
name := cfg.Name
pwd := cfg.Pwd
...
```### Different filename
The default filename for searching is
```
config.yaml
```You can set the filename with:
```golang
cfg := &Configuration{}
err := NewConfigLoader().File("myownconfigfile.yml").LoadConfig( c)
name := cfg.Name
pwd := cfg.Pwd
...
```