configurator

package module
v0.0.0-...-40dba60 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2018 License: MIT Imports: 7 Imported by: 0

README

Configurator

pipeline status coverage report Go Report Card GoDoc

A simple, highly opinionated, library to load a configuration. Heavily based on the recommendations from Kelsey Hightower's 12-fractured-apps post. This extends his library envconfig to add in the ability to also load from a yaml configuration file.

This library has only one public function which expects to be passed a struct specifying the configuration and containing the default values.

func LoadConfig(config interface{}, prefix string) error

This will the over-ride the defaults by loading with the following order (from lowest priority to highest):

  1. configuration file (yaml)
  • from config.yml (the library default, lowest priority)
  • from value specified by the CONFIG environment variable (with prefixing as described below)
  1. environment variables
  • optionally specify a prefix, eg: app will result in APP_VAR
  • for more information on using environment variables see the envconfig usage

Documentation

Overview

Package configurator implements a simple library for loading configurations.

The library overrides values in a default configuration from the following sources listed in increasing precedence.

A yaml configuration file (default, application specified, or passed with -config command line flag).

From environmental variables, optionally with an application specific prefix. Currently the library only support loading int and string type values.

The goal is to gracefully handle enough common cases with minimal dependencies and complexity. Getting a configuration loaded should be as simple as am single function call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(config interface{}, prefix string) error

LoadConfig takes a default configuration and updates it with values specified in a file or passed through the environment. config must be a pointer to a struct and should contain the default configuration values.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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