GConfig is a go library to handle configuration file and environment variables.
It uses viper and koanf to handle env vars and configuration file.
Install
go get -u github.com/platform-horizon/gconfig
Usage
Read Environment variables
type EnvironmentVariables struct {
LogLevel string
HTTPPort string
}
var envVariablesConfig = []gconfig.EnvConfig{
{
Key: "LOG_LEVEL",
Variable: "LogLevel",
Required: true
},
{
Key: "HTTP_PORT",
Variable: "HTTPPort",
},
}
var env EnvironmentVariables
if err := gconfig.GetEnvVariables(envVariablesConfig, &env); err != nil {
panic(err.Error())
}
Read from file
type ConfigurationFileVariables struct {
LogLevel string
HTTPPort string
}
var configuration ConfigurationFileVariables
if err := gconfig.GetConfigFromFile("config.test", ".", &configuration); err != nil {
panic(err.Error())
}
Versioning
We use SemVer for versioning. For the versions available,
see the tags on this repository.
License
This project is licensed under the Apache License 2.0 - see the LICENSE.md
file for details