config

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: CC0-1.0 Imports: 8 Imported by: 0

README

api-candidate abi-alpha Build Status CC0-1.0

config

Config reads and merges configuration from multiple sources associated with an application in the current execution environment.

License

This library is truly free, not GNU-encumbered "free software". Use it for any purpose, even commercial. Attribution is appreciated but not required.

Installation

go get -u github.com/amy911/env911/config

Imports

import "github.com/amy911/env911/config"

Usage Examples

Coming soon.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func App

func App() app.Apper

App gets the app being configured.

func AutoBind

func AutoBind() bool

AutoBind gets whether or not to use automatic environment variable binding.

func Env

func Env() map[string]interface{}

Env gets the map of keys to values configured via environment variables.

func Get

func Get(key string) interface{}

Get gets the value associated with key from the configuration sources

func Init

func Init(config Configger, onFail ...onfail.OnFail)

Init initializes the configuration for this app.

func Load

func Load()

Load loads mappings from the several sources.

func LoadEnv

func LoadEnv()

LoadEnv loads mappings from environment variables.

func LoadLocal

func LoadLocal() error

LoadLocal loads mappings from the local configuration file.

func LoadSystem

func LoadSystem() error

LoadSystem loads mappings from the system configuration file.

func Local

func Local() map[string]interface{}

Local gets the map of keys to values configured locally.

func Prefix

func Prefix() string

Prefix gets the environment variable prefix.

func System

func System() map[string]interface{}

System gets the map of keys to values configured system-wide.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config describes the app configuration.

func New

func New(app app.Apper, flagSet Flagger, prefix string, args ...interface{}) *Config

New creates a new Config.

func (*Config) App

func (config *Config) App() app.Apper

App gets the app being configured.

func (*Config) AutoBind

func (config *Config) AutoBind() bool

AutoBind gets whether or not to use automatic environment variable binding.

func (*Config) Bind

func (config *Config) Bind(key string) *Config

Bind binds the an environment key.

func (*Config) Bool

func (config *Config) Bool(name string, value bool, usage string)

func (*Config) BoolP

func (config *Config) BoolP(name, shorthand string, value bool, usage string)

func (*Config) BoolVar

func (config *Config) BoolVar(p *bool, name string, value bool, usage string)

func (*Config) BoolVarP

func (config *Config) BoolVarP(p *bool, name, shorthand string, value bool, usage string)

func (*Config) Count

func (config *Config) Count(name string, by int, usage string)

func (*Config) CountP

func (config *Config) CountP(name, shorthand string, by int, usage string)

func (*Config) CountVar

func (config *Config) CountVar(p *int, name string, by int, usage string)

func (*Config) CountVarP

func (config *Config) CountVarP(p *int, name, shorthand string, by int, usage string)

func (*Config) Env

func (config *Config) Env() map[string]interface{}

Env gets the map of keys to values configured via environment variables.

func (*Config) FlagSet

func (config *Config) FlagSet() Flagger

FlagSet gets the flag set used for configuration.

func (*Config) Get

func (config *Config) Get(key string) interface{}

Get gets the value associated with key from the configuration sources

func (*Config) Init

func (config *Config) Init(app app.Apper, flagSet Flagger, prefix string, args ...interface{}) *Config

Init initializes a Config.

func (*Config) Int

func (config *Config) Int(name string, value int, usage string)

func (*Config) IntP

func (config *Config) IntP(name, shorthand string, value int, usage string)

func (*Config) IntVar

func (config *Config) IntVar(p *int, name string, value int, usage string)

func (*Config) IntVarP

func (config *Config) IntVarP(p *int, name, shorthand string, value int, usage string)

func (*Config) Load

func (config *Config) Load() *Config

Load loads mappings from the several sources.

func (*Config) LoadAndParse

func (config *Config) LoadAndParse()

func (*Config) LoadEnv

func (config *Config) LoadEnv()

LoadEnv loads mappings from environment variables.

func (*Config) LoadLocal

func (config *Config) LoadLocal() error

LoadLocal loads mappings from the local configuration file.

func (*Config) LoadSystem

func (config *Config) LoadSystem() error

LoadSystem loads mappings from the system configuration file.

func (*Config) Local

func (config *Config) Local() map[string]interface{}

Local gets the map of keys to values configured locally.

func (*Config) Parse

func (config *Config) Parse(arguments []string) error

Parse parses flags on the command line.

func (*Config) Prefix

func (config *Config) Prefix() string

Prefix gets the environment variable prefix.

func (*Config) QueueStore

func (config *Config) QueueStore(key string, value interface{}) *Config

QueueStore queues a single key-value pair for storage into the local configuration file upon the next call to Save.

func (*Config) Save

func (config *Config) Save() error

Save atomically saves changes to the local configuration file.

func (*Config) SetAutoBind

func (config *Config) SetAutoBind(value bool) *Config

SetAutoBind sets whether or not to use automatic environment variable binding.

func (*Config) SetPrefix

func (config *Config) SetPrefix(value string) *Config

SetPrefix sets the environment variable prefix.

func (*Config) String

func (config *Config) String(name, value, usage string)

func (*Config) StringP

func (config *Config) StringP(name, shorthand, value string, usage string)

func (*Config) StringVar

func (config *Config) StringVar(p *string, name, value, usage string)

func (*Config) StringVarP

func (config *Config) StringVarP(p *string, name, shorthand, value string, usage string)

func (*Config) System

func (config *Config) System() map[string]interface{}

System gets the map of keys to values configured system-wide.

type Configger

type Configger interface {

	// App gets the app being configured.
	App() app.Apper

	// AutoBind gets whether or not to use automatic environment variable binding.
	AutoBind() bool

	// Bind binds the an environment key.
	Bind(string) Configger

	// Forward the call to the Flagger.
	Bool(name string, value bool, usage string)

	// Forward the call to the Flagger.
	BoolP(name, shorthand string, value bool, usage string)

	// Forward the call to the Flagger.
	BoolVar(p *bool, name string, value bool, usage string)

	// Forward the call to the Flagger.
	BoolVarP(p *bool, name, shorthand string, value bool, usage string)

	// Forward the call to the Flagger.
	Count(name string, by int, usage string)

	// Forward the call to the Flagger.
	CountP(name, shorthand string, by int, usage string)

	// Forward the call to the Flagger.
	CountVar(p *int, name string, by int, usage string)

	// Forward the call to the Flagger.
	CountVarP(p *int, name, shorthand string, by int, usage string)

	// Env gets the map of keys to values configured via environment variables.
	Env() map[string]interface{}

	// FlagSet gets the flag set used for configuration.
	FlagSet() Flagger

	// Get gets the value associated with key from the configuration sources
	Get(key string) interface{}

	// Forward the call to the Flagger.
	Int(name string, value int, usage string)

	// Forward the call to the Flagger.
	IntP(name, shorthand string, value int, usage string)

	// Forward the call to the Flagger.
	IntVar(p *int, name string, value int, usage string)

	// Forward the call to the Flagger.
	IntVarP(p *int, name, shorthand string, value int, usage string)

	// Load loads mappings from the several sources.
	Load() Configger

	// Load and Parse.
	LoadAndParse()

	// LoadEnv loads mappings from environment variables.
	LoadEnv()

	// LoadLocal loads mappings from the local configuration file.
	LoadLocal() error

	// LoadSystem loads mappings from the system configuration file.
	LoadSystem() error

	// Local gets the map of keys to values configured locally.
	Local() map[string]interface{}

	// Parse parses flags on the command line.
	Parse(arguments []string) error

	// Prefix gets the environment variable prefix.
	Prefix() string

	// QueueStore queues a single key-value pair for storage into the local configuration file upon the next call to Save.
	QueueStore(string, interface{}) Configger

	// Save atomically saves changes to the local configuration file.
	Save() error

	// SetAutoBind sets whether or not to use automatic environment variable binding.
	SetAutoBind(bool) Configger

	// SetPrefix sets the environment variable prefix.
	SetPrefix(string) Configger

	// Forward the call to the Flagger.
	String(name, value, usage string)

	// Forward the call to the Flagger.
	StringP(name, shorthand, value string, usage string)

	// Forward the call to the Flagger.
	StringVar(p *string, name, value, usage string)

	// Forward the call to the Flagger.
	StringVarP(p *string, name, shorthand, value string, usage string)

	// System gets the map of keys to values configured system-wide.
	System() map[string]interface{}
}

Configger is the interface for app configuration.

func Bind

func Bind(key string) Configger

Bind binds the an environment key.

func SetAutoBind

func SetAutoBind(value bool) Configger

SetAutoBind sets whether or not to use automatic environment variable binding.

func SetPrefix

func SetPrefix(value string) Configger

SetPrefix sets the environment variable prefix.

type Flagger

type Flagger interface {
	Bool(string, bool, string)
	BoolP(string, string, bool, string)
	BoolVar(*bool, string, bool, string)
	BoolVarP(*bool, string, string, bool, string)
	Count(string, int, string)
	CountP(string, string, int, string)
	CountVar(*int, string, int, string)
	CountVarP(*int, string, string, int, string)
	CountWorks() bool
	Int(string, int, string)
	IntP(string, string, int, string)
	IntVar(*int, string, int, string)
	IntVarP(*int, string, string, int, string)
	Parse([]string) error
	String(string, string, string)
	StringP(string, string, string, string)
	StringVar(*string, string, string, string)
	StringVarP(*string, string, string, string, string)
}

Flagger is the interface for a flag replacement library.

func FlagSet

func FlagSet() Flagger

FlagSet gets the flag set used for configuration.

type PFlag

type PFlag struct {
	pflag.FlagSet
}

func (PFlag) Count

func (pflag PFlag) Count(name string, usage string)

func (PFlag) CountP

func (pflag PFlag) CountP(name, shorthand string, usage string)

func (PFlag) CountVar

func (pflag PFlag) CountVar(p *int, name string, usage string)

func (PFlag) CountVarP

func (pflag PFlag) CountVarP(p *int, name, shorthand string, usage string)

func (PFlag) CountWorks

func (pflag PFlag) CountWorks() bool

Jump to

Keyboard shortcuts

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