Documentation ¶
Index ¶
- Variables
- func AddDefaultDirs(name string)
- func AddFile(name string)
- func AddFilepath(filepath string)
- func AddPath(path string)
- func AddUserConfigDir(dirname string) error
- func AddUserHomeDir(name string) error
- func BindToFlagSet(set *flag.FlagSet, resolvers ...FlagInfo)
- func BindToPFlagSet(set *pflag.FlagSet, resolvers ...FlagInfo)
- func DirUsed() stringdeprecated
- func FileUsed() stringdeprecated
- func FilesUsed() []string
- func Get(key string) interface{}
- func GetBool(key string) bool
- func GetBoolErr(key string) (bool, error)
- func GetConfig() interface{}
- func GetErr(key string) (interface{}, error)
- func GetFloat(key string) float64
- func GetFloat32(key string) float32
- func GetFloat32Err(key string) (float32, error)
- func GetFloat64(key string) float64
- func GetFloat64Err(key string) (float64, error)
- func GetFloatErr(key string) (float64, error)
- func GetInt(key string) int
- func GetInt32(key string) int32
- func GetInt32Err(key string) (int32, error)
- func GetInt64(key string) int64
- func GetInt64Err(key string) (int64, error)
- func GetInt64Slice(key string) []int64
- func GetIntErr(key string) (int, error)
- func GetIntSlice(key string) []int
- func GetString(key string) string
- func GetStringErr(key string) (string, error)
- func GetStringMap(key string) map[string]string
- func GetUint(key string) uint
- func GetUint32(key string) uint32
- func GetUint32Err(key string) (uint32, error)
- func GetUint64(key string) uint64
- func GetUint64Err(key string) (uint64, error)
- func GetUintErr(key string) (uint, error)
- func Getenv(key string) string
- func HasKey(key string) bool
- func HomeDir() string
- func InitDefaults() error
- func IsEmpty(key string) bool
- func NewConfigCommand() *cobra.Command
- func Paths() []string
- func PathsUsed() []string
- func ReadConfig() error
- func ReadConfigFile() errordeprecated
- func ReadConfigFromFile(filepath string) errordeprecated
- func ReadConfigNoOverwrite() error
- func RemoveFile(name string)
- func RemovePath(path string)
- func SetConfig(conf interface{}) error
- func SetFilename(name string)deprecated
- func SetNestedFlagDelim(delim rune)
- func SetType(ext string) error
- func Updated() (<-chan struct{}, error)
- func Watch() error
- type Config
- func (c *Config) AddFile(name string)
- func (c *Config) AddFilepath(filepath string)
- func (c *Config) AddPath(path string)
- func (c *Config) AddUserConfigDir(dirname string) error
- func (c *Config) AddUserHomeDir(name string) error
- func (c *Config) BindToFlagSet(set *flag.FlagSet, resolvers ...FlagInfo)
- func (c *Config) BindToPFlagSet(set *pflag.FlagSet, resolvers ...FlagInfo)
- func (c *Config) DirUsed() stringdeprecated
- func (c *Config) FileUsed() stringdeprecated
- func (c *Config) FilesUsed() []string
- func (c *Config) Get(key string) interface{}
- func (c *Config) GetBool(key string) bool
- func (c *Config) GetBoolErr(key string) (bool, error)
- func (c *Config) GetConfig() interface{}
- func (c *Config) GetErr(key string) (interface{}, error)
- func (c *Config) GetFloat(key string) float64
- func (c *Config) GetFloat32(key string) float32
- func (c *Config) GetFloat32Err(key string) (float32, error)
- func (c *Config) GetFloat64(key string) float64
- func (c *Config) GetFloat64Err(key string) (float64, error)
- func (c *Config) GetFloatErr(key string) (float64, error)
- func (c *Config) GetInt(key string) int
- func (c *Config) GetInt32(key string) int32
- func (c *Config) GetInt32Err(key string) (int32, error)
- func (c *Config) GetInt64(key string) int64
- func (c *Config) GetInt64Err(key string) (int64, error)
- func (c *Config) GetInt64Slice(key string) []int64
- func (c *Config) GetIntErr(key string) (int, error)
- func (c *Config) GetIntSlice(key string) []int
- func (c *Config) GetString(key string) string
- func (c *Config) GetStringErr(key string) (string, error)
- func (c *Config) GetStringMap(key string) map[string]string
- func (c *Config) GetUint(key string) uint
- func (c *Config) GetUint32(key string) uint32
- func (c *Config) GetUint32Err(key string) (uint32, error)
- func (c *Config) GetUint64(key string) uint64
- func (c *Config) GetUint64Err(key string) (uint64, error)
- func (c *Config) GetUintErr(key string) (uint, error)
- func (c *Config) Getenv(key string) string
- func (c *Config) HasKey(key string) bool
- func (c *Config) InitDefaults() error
- func (c *Config) IsEmpty(key string) bool
- func (c *Config) NewConfigCommand() *cobra.Command
- func (c *Config) Paths() []string
- func (c *Config) PathsUsed() []string
- func (c *Config) ReadConfig() error
- func (c *Config) ReadConfigFile() errordeprecated
- func (c *Config) ReadConfigFromFile(filepath string) errordeprecated
- func (c *Config) ReadConfigNoOverwrite() error
- func (c *Config) ReloadOn(sig ...os.Signal)
- func (c *Config) RemoveFile(name string)
- func (c *Config) RemovePath(path string)
- func (c *Config) SetConfig(conf interface{}) error
- func (c *Config) SetFilename(name string)deprecated
- func (c *Config) SetType(t string) error
- func (c *Config) Updated() (<-chan struct{}, error)
- func (c *Config) UseDefaultDirs(dirname string)
- func (c *Config) Watch() error
- type Flag
- type FlagInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoConfigFile is returned when the config file cannot be found. ErrNoConfigFile = errors.New("no config file") // ErrNoConfigDir is returned when all of the possible config paths // do not exist. ErrNoConfigDir = errors.New("no config directory") // ErrFieldNotFound is returned when the field of a struct // was not found with reflection ErrFieldNotFound = errors.New("could not find struct field") // ErrWrongType is returned when the wrong type is used ErrWrongType = errors.New("wrong type") )
var IndentedCobraHelpTemplate = `` /* 936-byte string literal not displayed */
This is a template for cobra commands that more closely imitates the style of the go command help message.
Functions ¶
func AddDefaultDirs ¶
func AddDefaultDirs(name string)
AddDefaultDirs sets the config and home directories as possible config dir options.
If the config dir is found (see os.UserConfigDir) then <config dir>/<name> is added to the list of possible config paths. If the home dir is found (see os.UserHomeDir) then <home dir>/<name> is added to the list of possible config paths.
func AddFile ¶ added in v0.1.2
func AddFile(name string)
AddFile will add a filename to the list of possible config filenames. This should be the name of a file without any information about the directory or location.
A path and filename could be used and will be treated as relative to any of the paths added with AddPath but is behavior which is not guaranteed to be supported in the future.
To add a directory to the search path, use AddPath.
func AddFilepath ¶ added in v0.1.4
func AddFilepath(filepath string)
AddFilepath will add a full filepath to the list of possible config files. This is not the same as adding the path and filename separately. This does not add a search path or filename to search for and should be regarded as hard coding a configuration filepath.
func AddPath ¶
func AddPath(path string)
AddPath will add a path the the list of possible configuration folders where a file could be found. See AddFile to add a file to the list of possible files to be read within a configuration search path.
func AddUserConfigDir ¶ added in v0.1.3
AddUserConfigDir will add a config dir using the user config dir (see os.UserConfigDir) and join it with the name given.
$XDG_CONFIG_DIR/<dirname>
func AddUserHomeDir ¶ added in v0.1.3
AddUserHomeDir will add a config dir using the user home dir (see os.UserHomeDir) and join it with the name given and a "."
$HOME/.<name>
func BindToFlagSet ¶ added in v0.1.0
BindToFlagSet will bind the config struct to a standard library flag set
func BindToPFlagSet ¶ added in v0.1.0
BindToPFlagSet will bind the config object to a pflag set. See https://pkg.go.dev/github.com/spf13/pflag?tab=doc
func FilesUsed ¶ added in v0.1.4
func FilesUsed() []string
FilesUsed will return a list of all the configuration files that exist within the specified search space. This are the same files used when calling ReadConfig.
func GetBoolErr ¶
GetBoolErr will get a boolean value but return an error is something went wrong.
func GetConfig ¶
func GetConfig() interface{}
GetConfig will return the the config struct that has been set by the user but as an interface type.
func GetErr ¶
GetErr will get the value stored at some key and return an error if something went wrong.
func GetFloat32 ¶
func GetFloat32Err ¶ added in v0.1.3
func GetFloat64 ¶ added in v0.1.3
func GetFloat64Err ¶ added in v0.1.3
func GetFloatErr ¶ added in v0.1.3
func GetInt32Err ¶ added in v0.1.3
func GetInt64Err ¶ added in v0.1.3
func GetInt64Slice ¶
GetInt64Slice will return a slice of int64.
Warning: will panic if the key given does not reference a []int64
func GetIntErr ¶
GetIntErr will return an get an int but also return an error if something went wrong, main just missing keys and conversion errors
func GetIntSlice ¶
GetIntSlice will get a slice of ints from a key
func GetStringErr ¶
GetStringErr is the same as get string but it returns an error when something went wrong, mainly if the key does not exist
func GetStringMap ¶
GetStringMap will get a map of string keys to string values
func GetUint32Err ¶ added in v0.1.3
func GetUint64Err ¶ added in v0.1.3
func GetUintErr ¶ added in v0.1.3
func InitDefaults ¶ added in v0.1.0
func InitDefaults() error
InitDefaults will find all the default values and set each struct field accordingly.
func IsEmpty ¶
IsEmpty returns true if the value stored at some key is a zero value or an empty value
func NewConfigCommand ¶ added in v0.0.2
NewConfigCommand creates a new cobra command for configuration
func Paths ¶ added in v0.1.0
func Paths() []string
Paths returns the slice of folder paths that will be searched when looking for a config file.
func PathsUsed ¶ added in v0.1.4
func PathsUsed() []string
PathsUsed will return all configuration paths where there is an existing configuration file.
func ReadConfig ¶ added in v0.1.2
func ReadConfig() error
ReadConfig will read all the config files.
If multiple config files are found, then the first ones found will have the highest precedence and the following config files will not overwrite existing values.
func ReadConfigFile
deprecated
func ReadConfigFile() error
Deprecated: use ReadConfig
func ReadConfigFromFile
deprecated
added in
v0.1.3
func ReadConfigNoOverwrite ¶ added in v0.1.4
func ReadConfigNoOverwrite() error
ReadConfigNoOverwrite will read all config files but will not overwrite fields on the config struct if they are not a zero value.
func RemoveFile ¶ added in v0.1.4
func RemoveFile(name string)
RemoveFile will remove a filename from the list of config files names. Essentially the inverse operation of AddFilename.
func RemovePath ¶ added in v0.1.4
func RemovePath(path string)
RemovePath will remove a path from the list of possible config file locations.
func SetFilename
deprecated
func SetFilename(name string)
Deprecated: Use AddFile
func SetNestedFlagDelim ¶ added in v0.1.2
func SetNestedFlagDelim(delim rune)
SetNestedFlagDelim changed the character used to seperate the names of nested flags.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds configuration metadata
func New ¶
func New(conf interface{}) *Config
New creates a new config object from a configuration struct.
func (*Config) AddFile ¶ added in v0.1.2
AddFile will add a filename to the list of possible config filenames. This should be the name of a file without any information about the directory or location.
A path and filename could be used and will be treated as relative to any of the paths added with AddPath but is behavior which is not guaranteed to be supported in the future.
To add a directory to the search path, use AddPath.
func (*Config) AddFilepath ¶ added in v0.1.4
AddFilepath will add a full filepath to the list of possible config files. This is not the same as adding the path and filename separately. This does not add a search path or filename to search for and should be regarded as hard coding a configuration filepath.
func (*Config) AddPath ¶
AddPath will add a path the the list of possible configuration folders where a file could be found. See AddFile to add a file to the list of possible files to be read within a configuration search path.
func (*Config) AddUserConfigDir ¶ added in v0.1.3
AddUserConfigDir will add a config dir using the user config dir (see os.UserConfigDir) and join it with the name given.
$XDG_CONFIG_DIR/<dirname>
func (*Config) AddUserHomeDir ¶ added in v0.1.3
AddUserHomeDir will add a config dir using the user home dir (see os.UserHomeDir) and join it with the name given and a "."
$HOME/.<name>
func (*Config) BindToFlagSet ¶ added in v0.1.0
BindToFlagSet will bind the config struct to a standard library flag set
func (*Config) BindToPFlagSet ¶ added in v0.1.0
BindToPFlagSet will bind the config object to a pflag set. See https://pkg.go.dev/github.com/spf13/pflag?tab=doc
func (*Config) FilesUsed ¶ added in v0.1.4
FilesUsed will return a list of all the configuration files that exist within the specified search space. This are the same files used when calling ReadConfig.
func (*Config) GetBoolErr ¶
GetBoolErr will get a boolean value but return an error is something went wrong.
func (*Config) GetConfig ¶
func (c *Config) GetConfig() interface{}
GetConfig will return the the config struct that has been set by the user but as an interface type.
func (*Config) GetErr ¶
GetErr will get the value stored at some key and return an error if something went wrong.
func (*Config) GetFloat32 ¶
func (*Config) GetFloat32Err ¶ added in v0.1.3
func (*Config) GetFloat64 ¶ added in v0.1.3
func (*Config) GetFloat64Err ¶ added in v0.1.3
func (*Config) GetFloatErr ¶ added in v0.1.3
func (*Config) GetInt32Err ¶ added in v0.1.3
func (*Config) GetInt64Err ¶ added in v0.1.3
func (*Config) GetInt64Slice ¶
GetInt64Slice will return a slice of int64.
Warning: will panic if the key given does not reference a []int64
func (*Config) GetIntErr ¶
GetIntErr will return an get an int but also return an error if something went wrong, main just missing keys and conversion errors
func (*Config) GetIntSlice ¶
GetIntSlice will get a slice of ints from a key
Warning: will panic if the key does not reference a []int
func (*Config) GetString ¶
GetString will get the config value by name and return it as a string. This function will also expand any environment variables in the value returned.
func (*Config) GetStringErr ¶
GetStringErr is the same as get string but it returns an error when something went wrong, mainly if the key does not exist
func (*Config) GetStringMap ¶
GetStringMap will get a map of string keys to string values
func (*Config) GetUint32Err ¶ added in v0.1.3
func (*Config) GetUint64Err ¶ added in v0.1.3
func (*Config) InitDefaults ¶ added in v0.1.0
InitDefaults will find all the default values and set each struct field accordingly.
func (*Config) IsEmpty ¶
IsEmpty returns true if the value stored at some key is a zero value or an empty value
func (*Config) NewConfigCommand ¶ added in v0.1.4
func (*Config) Paths ¶ added in v0.1.0
Paths returns the slice of folder paths that will be searched when looking for a config file.
func (*Config) PathsUsed ¶ added in v0.1.4
PathsUsed will return all configuration paths where there is an existing configuration file.
func (*Config) ReadConfig ¶ added in v0.1.2
ReadConfig will read all the config files.
If multiple config files are found, then the first ones found will have the highest precedence and the following config files will not overwrite existing values.
func (*Config) ReadConfigFile
deprecated
func (*Config) ReadConfigFromFile
deprecated
added in
v0.1.3
func (*Config) ReadConfigNoOverwrite ¶ added in v0.1.4
ReadConfigNoOverwrite will read all config files but will not overwrite fields on the config struct if they are not a zero value.
func (*Config) ReloadOn ¶ added in v0.1.3
ReloadOn takes a list of signals and will reload the config whenever any of them are received.
func (*Config) RemoveFile ¶ added in v0.1.4
RemoveFile will remove a filename from the list of config files names. Essentially the inverse operation of AddFilename.
func (*Config) RemovePath ¶ added in v0.1.4
RemovePath will remove a path from the list of possible config file locations.
func (*Config) SetFilename
deprecated
func (*Config) Updated ¶ added in v0.1.2
Updated will return a channel which will never close and will recieve an empty struct every time a config file is created, or written to.
func (*Config) UseDefaultDirs ¶
UseDefaultDirs sets the config and home directories as possible config dir options.
If the config dir is found (see os.UserConfigDir) then "<config dir>/<name>" is added to the list of possible config paths. If the home dir is found (see os.UserHomeDir) then "<home dir>/.<name>" is added to the list of possible config paths.
These paths are added the list (its different for windows)
$XDG_CONFIG_DIR/<name> $HOME/.<name>