Opinionated config validator, parser and merger for Go
Configurator provides a pluggable way to parse, validate and merge configuration for applications across files, environment variables and cli flag arguments.
# Core
go get github.com/matthewhartstonge/configurator
Check out the example application with a full example.
Documentation is hosted at godoc
Each parser is stored in a separate package due to pulling in 3rd-party dependencies. This ensures that your build is kept slim - includes what you need and nothing that you don't.
package main
// Define your own FileConfig{}, EnvConfig{} and FlagConfig{}
import (
"fmt"
"time"
"github.com/matthewhartstonge/configurator"
"github.com/matthewhartstonge/configurator/env/envconfig"
"github.com/matthewhartstonge/configurator/file/hcl"
"github.com/matthewhartstonge/configurator/file/json"
"github.com/matthewhartstonge/configurator/file/toml"
"github.com/matthewhartstonge/configurator/file/yaml"
)
func main() {
cfg := &configurator.Config{
AppName: "ExampleApp",
Domain: defaults,
File: []configurator.ConfigTypeable{
yaml.New(&FileConfig{}),
toml.New(&FileConfig{}),
json.New(&FileConfig{}),
hcl.New(&FileConfig{}),
},
Env: envconfig.New(&EnvConfig{}),
Flag: nil, // TODO: implement flag parsers
}
config, err := configurator.New(cfg)
if err != nil {
panic(err)
}
// Print out the processed config:
fmt.Printf("%+v\n", config.Domain)
}
- CLI Flag parsing
- Full documentation for developer happiness
- What are the interfaces required to be implemented?