Documentation ¶
Index ¶
- type Basis
- type Config
- func (c *Config) Default(x interface{}) *string
- func (c *Config) Executable() *string
- func (c *Config) FileFromExecutable() string
- func (c *Config) FileFromHome() string
- func (c *Config) Find(list ...string) string
- func (c *Config) FindAndLoad(list ...string) string
- func (c *Config) FromEnv(key string) *string
- func (c *Config) FromFile(key string) *string
- func (c *Config) Load(filename string)
- func (c *Config) ResolveBool(list ...*string) bool
- func (c *Config) ResolveFloat64(list ...*string) float64
- func (c *Config) ResolveInt(list ...*string) int
- func (c *Config) ResolveString(list ...*string) string
- func (c *Config) UserConfigDir() *string
- func (c *Config) UserHomeDir() *string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Basis ¶
type Basis int
Basis is an enum used for indicating the basis for locating the config file.
type Config ¶
type Config struct { AppName string // Application name FileBase string // Base name for config file, default "config" Location Basis // Where to locate the config, default ORelativeToUser Errors []error // List of errors encountered while trying to load the config TrueStrings []string // String values which count as `true` (case-insensitive), default `["true"]` FalseStrings []string // String values which count as `false` (case-insensitive), default `["false"]` // contains filtered or unexported fields }
Config stores parameters and data needed for loading the configuration from files and the environment.
func New ¶
New returns a Config object which can be used to look up configuration values from the environment and from a TOML file.
func (*Config) Default ¶
Default wraps an int, bool or string value to act as default when resolving config values.
func (*Config) Executable ¶
Executable is a wrapped version of os.Executable which appends any error to Config.Errors.
func (*Config) FileFromExecutable ¶
FileFromExecutable computes the config file name based on the location of executable. Used for cloud applications.
func (*Config) FileFromHome ¶
FileFromHome looks for the config file in the standard location for the user's OS, as per Go's `os.UserConfigDir`. Example default filenames:
Linux: ~/.config/AppName/config.toml Mac: ~/Library/Application Support/AppName/config.toml Windows: %AppData%\AppName\config.toml
func (*Config) Find ¶
Find locates the first extant TOML file by checking the supplied list of possible locations. Empty strings are ignored. It returns the filename.
func (*Config) FindAndLoad ¶
FindAndLoad locates the first config file from the list of possibilities, then loads it. Empty strings are ignored, and the name of the file that was loaded is returned. It's equivalent to Find followed by Load.
func (*Config) FromEnv ¶
FromEnv looks for a value in an environment variable with the specified name.
func (*Config) FromFile ¶
FromFile obtains a configuration value from the TOML config file, given a string key.
func (*Config) Load ¶
Load loads the TOML config file specified. Any errors are appended to Config.Errors
func (*Config) ResolveBool ¶
ResolveBool loops through the listed possible values to find a non-missing one, then parses it and casts it to a boolean. If no values are present, you get the zero boolean value `false`.
func (*Config) ResolveFloat64 ¶
ResolveFloat64 loops through the listed possible values to find a non-missing one, then parses it and casts it to a float64. If no values are present, you get the zero value.
func (*Config) ResolveInt ¶
ResolveInt loops through the listed possible values to find a non-missing one, then parses it and casts it to an integer. If no values are present, you get the zero integer value `0`. Floating point values are rounded down.
func (*Config) ResolveString ¶
ResolveString loops through the listed possible values to find a non-missing one, and return it. If no values are present, you get the zero string `""`.
func (*Config) UserConfigDir ¶
UserConfigDir is a wrapped version of os.UserConfigDir which appends any error to Config.Errors.
func (*Config) UserHomeDir ¶
UserHomeDir is a wrapped version of os.UserHomeDir which appends any error to Config.Errors.