config

package module
v0.0.0-...-414270c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2020 License: MIT Imports: 9 Imported by: 0

README

Config

A simple means of updating configuration provided

Example

This package leverages previous work of utilising struct tags in order to caputre desired inputs.

Environment parsing is handled by envconfig.
Flag parsing is handled by go-flags.

In order to utilise it, you can do something like the following:

type Values struct {
  LogLevel  string `long:"log-level" description:"Set the logging level for the application"`
  EnvSecret string `envconfig:"env_secret" split_words:"true"`
}

func example() {
  v := &Values{LogLevel: "info"}
  conf := config.Default(v)
  if err := conf.ParseFlags().ParseEnv().Err(); err != nil {
    panic(err)
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	// Err returns any internal errors that happened while processing input
	Err() error

	// From allows for reading from a writer and applying to the config
	From(data io.Reader) Config

	// ParseEnv reads from the environment and will apply the found values
	// to the fields configured.
	ParseEnv() Config

	// ParseFlags will take an array of input and parse them
	// applying to the internal config.
	ParseFlags(args []string) Config
}

Config defines a basic interface that allows for wrapping behaviour for a nice config object

func Default

func Default(values interface{}) Config

Default wraps the values and provides support for the configuration builder It will set the default decoder as json

func WithDecoding

func WithDecoding(value interface{}, decode string) (Config, error)

WithDecoding allows for a custom decoder to be used when running `From` if there is no valid decode, an error is returned.

Valid decodings are yaml, json, or toml.

type Decoder

type Decoder interface {
	Decode(value interface{}) error
}

Decoder allows for dynamic decodings for configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL