Skip to content

Latest commit

 

History

History
77 lines (58 loc) · 1.94 KB

README.md

File metadata and controls

77 lines (58 loc) · 1.94 KB

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?