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 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...
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.
Click to show internal directories.
Click to hide internal directories.