Config lib is a library to handle configuration in your program.
It handles config file and environments variables.
It uses viper and koanf to handle, respectively, env variables and configuration.
This library handle json in a case sensitive mode.
Install
go get -u github.com/mia-platform/configlib
Example usage
Load file service json configuration - with json schema validation
type Config struct {}
func loadServiceConfiguration(path, fileName string) (Config, error) {
jsonSchema, err := configlib.ReadFile(configSchemaPath)
if err != nil {
return nil, err
}
var config ServiceConfig
if err := configlib.GetConfigFromFile(fileName, path, jsonSchema, &config); err != nil {
return nil, err
}
return config, err
}
// Load service configuration
config, err := loadServiceConfiguration("my/path", "file")
if err != nil {
log.Fatal(err.Error())
}
Load file service json configuration - without json schema validation
type Config struct {}
func loadServiceConfiguration(path, fileName string) (Config, error) {
var config ServiceConfig
if err := configlib.GetConfigFromFile(fileName, path, nil, &config); err != nil {
return nil, err
}
return config, err
}
// Load service configuration
config, err := loadServiceConfiguration("my/path", "file")
if err != nil {
log.Fatal(err.Error())
}
Get env variables
This feature is deprecated. Please use another lib, like this.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct,
and the process for submitting pull requests to us.
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
file for details