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"
    "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)
}

Todo

  • CLI Flag parsing
  • 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