conf

package module
v0.0.0-...-5699d1b Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2018 License: BSD-3-Clause Imports: 9 Imported by: 0

README

conf

MIT License Wip Build status Coverage status Go Report Card Github issues Github pull requests GoDoc

Documentation

Index

Constants

View Source
const (
	// Env directs the Configuration to read values from environment
	// variables.
	Env cnfSrc = iota
	// File directs the Configuration to read values from a file on the
	// local filesystem.
	File
)
View Source
const (
	// JSON directs the Configuration to expect JSON data.
	JSON cnfType = iota + 1
	// TOML directs the Configuration to expect TOML data.
	TOML
	// YAML directs the Configuration to expect YAML data.
	YAML
)
View Source
const (
	// Bool defines the boolean type.
	Bool valType = iota
	// Float defines the float type.
	Float
	// Int defines the integer type.
	Int
	// List defines the list type.
	List
	// Map defines the map type.
	Map
	// String defines the string type.
	String
)

Value type constants

View Source
const (
	// ErrInvalidValueType - The defined value type does not match the type requested
	ErrInvalidValueType errs.Code = iota + 1000
)

Internal errors

Variables

This section is empty.

Functions

func Del

func Del(name string)

Del removes a configuration from the global namespace.

func Set

func Set(
	name string,
	conf Configuration,
)

Set sets a Configuration in the global namespace.

Types

type Configuration

type Configuration interface {
	// AddPath adds a directory path to the file search path. Paths are
	// searched in FIFO order.
	AddPath(path string) *conf

	// Get retrieves a value by name.
	Get(name string) Valuer

	GetDefault(name string) Valuer

	// Name returns the configuration name. For a file-based config this
	// is the filename without the file extension.
	Name() string

	// Parse parses the configuration data.
	Parse() error

	// Path returns the list of file search paths.
	Path() []string

	// Read implements io.Reader
	Read(p []byte) (n int, err error)

	// Set sets a value in this configuration
	Set(name string, value Valuer) *conf

	// Define a default config value.
	SetDefault(name string, value Valuer) *conf

	// Define all default config values.
	SetDefaults(defaults map[string]Valuer) *conf

	// Define a prefix to use when accessing environment variables.
	// Environment variable names are case sensitive. Eg:
	//
	//	conf.SetEnvPrefix("SVC_")
	//	id := conf.Get("ID")
	SetEnvPrefix(prefix string) *conf

	// SetName sets the configuration name. For a file-based config this
	// is the filename without the file extension.
	SetName(name string) *conf

	// SetPath replaces the current file search path. Paths are searched
	// in FIFO order.
	SetPath(path []string) *conf

	// Watch watches configuration sources for changes and automatically
	// updates available values.
	Watch()
}

Configuration defines a configuration interface...

func Get

func Get(name string) Configuration

Get returns a value from teh global configuration.

func New

func New(
	name string,
	cnfSrc cnfSrc,
	cnfType cnfType,
	path []string,
	defaults map[string]Valuer,
	logger std.Logger,
) Configuration

New returns a new Configuration interface.

type ValueList

type ValueList []Valuer

ValueList is a list of Valuers.

type ValueMap

type ValueMap map[string]Valuer

ValueMap is a map of Valuers.

type Valuer

type Valuer interface {
	// Bool returns the boolean representation of the value, or an error if
	// the type conversion is not possible.
	Bool() (bool, error)
	// Float returns the float64 representation of the value, or an error if
	// the type conversion is not possible.
	Float() (float64, error)
	// Float32 returns the float32 representation of the value, or an error
	// if the type conversion is not possible.
	Float32() (float32, error)
	// Float64 returns the float64 representation of the value, or an error
	// if the type conversion is not possible.
	Float64() (float64, error)
	// Int returns the int representation of the value, or an error if the
	// type conversion is not possible.
	Int() (int, error)
	// List returns the ValueList representation of the value, or an error
	// if the type conversion is not possible.
	List() (ValueList, error)
	// Map returns the ValueMap representation of the value, or an error if
	// the type conversion is not possible.
	Map() (ValueMap, error)
	// String returns the boolean representation of the value, or an error
	// if the type conversion is not possible.
	String() (string, error)
}

Valuer is an interface that defines a configuration value.

func NewVal

func NewVal(
	valueType valType,
	valueData interface{},
) Valuer

Jump to

Keyboard shortcuts

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