https://github.com/leonsteinhaeuser/go-config
This repository provides a library that automatically detects the file extension and parses the data into the desired struct. If these steps were successful, the library will overload the parsed configuration with the desired environment variables.
https://github.com/leonsteinhaeuser/go-config
Last synced: 8 months ago
JSON representation
This repository provides a library that automatically detects the file extension and parses the data into the desired struct. If these steps were successful, the library will overload the parsed configuration with the desired environment variables.
- Host: GitHub
- URL: https://github.com/leonsteinhaeuser/go-config
- Owner: leonsteinhaeuser
- License: mit
- Created: 2022-02-09T18:27:14.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-25T10:01:50.000Z (over 3 years ago)
- Last Synced: 2025-09-26T21:59:29.120Z (9 months ago)
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-config
[](https://github.com/leonsteinhaeuser/go-config/actions/workflows/tests.yml)
[](https://codecov.io/gh/leonsteinhaeuser/go-config)
This repository provides a library that automatically detects the file extension and parses the data into the desired struct. If these steps were successful, the library will overload the parsed configuration with the desired environment variables.
## Example
```go
type Config struct {
IsAlive bool
Server struct {
Address string
Port int
}
}
func main() {
os.Setenv("CFG_ISALIVE", "true")
os.Setenv("CFG_SERVER_ADDRESS", "0.0.0.0")
os.Setenv("CFG_SERVER_PORT", "8491")
cfg := Config{}
AutoloadAndEnrichConfig("config.yml", &cfg)
// custom env prefix
os.Setenv("MYPREFIX_ISALIVE", "true")
os.Setenv("MYPREFIX_SERVER_ADDRESS", "0.0.0.0")
os.Setenv("MYPREFIX_SERVER_PORT", "8491")
cfg2 := Config{}
AutoloadAndEnrichConfigWithEnvPrefix("config.yml", "myprefix", &cfg2)
}
```