Skip to content

Opinionated config validator, parser and merger for Go

License

Notifications You must be signed in to change notification settings

matthewhartstonge/configurator

Repository files navigation

Configurator logo

Configurator

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.

Install configurator

# Core
go get github.com/matthewhartstonge/configurator

Example

Check out the example application with a full example.

Documentation

Documentation is hosted at godoc

Usage

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"
    
    "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"
    "github.com/matthewhartstonge/configurator/flag/stdflag"
)

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: stdflag.New(&FlagConfig{}),
	}
	config, err := configurator.New(cfg)
	if err != nil {
		panic(err)
	}
	
	// Print out the processed config:
	fmt.Printf("%+v\n", config.Domain)
}

Todo

  • Full documentation for developer happiness
    • What are the interfaces required to be implemented?

About

Opinionated config validator, parser and merger for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published