Documentation ¶
Index ¶
- func AddInitErr(err error)
- func ApplicationDataPath() string
- func InitApp(appName string) error
- func InitErr() error
- func SaveSettings(path string, s Settings) error
- type EnvMatcher
- type Option
- type Settings
- func (s Settings) Bool(path string) (bool, bool)
- func (s Settings) Float64(path string) (float64, bool)
- func (s Settings) Int64(path string) (int64, bool)
- func (s Settings) IsChanged() bool
- func (s Settings) Length(path string) int
- func (s Settings) MustBool(path string, fallback bool) bool
- func (s Settings) MustFloat64(path string, fallback float64) float64
- func (s Settings) MustInt64(path string, fallback int64) int64
- func (s Settings) MustString(path, fallback string) string
- func (s Settings) Print()
- func (s Settings) SetValue(key string, value interface{}) error
- func (s Settings) String(path string) (string, bool)
- func (s Settings) Strings(path string) []string
- func (s Settings) Subset(path string) Settings
- func (s Settings) WalkKeys(fn WalkKeysFunc) error
- type WalkKeysFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddInitErr ¶
func AddInitErr(err error)
func AddInitErr adds an error to the init error list. This is checked only during startup, to deal with any errors generated by init() funcs.
func ApplicationDataPath ¶
func ApplicationDataPath() string
func InitApp ¶
InitApp supplies names to any paths that want to use the application name, such as the AppDataPath.
func InitErr ¶
func InitErr() error
func InitErr answers a composition of errors generated during init() funcs, if any.
func SaveSettings ¶
SaveSettings saves the settings as JSON to the path. It will remove any private keys.
Types ¶
type EnvMatcher ¶
type EnvMatcher interface { // Answer a key if a match, or else "". The key // might be the same key in the args, or it might be modified. Match(key string) (string, error) }
EnvMatcher is used by WithEnv to accept env vars and potentially modify the name.
func EnvPattern ¶
func EnvPattern(pattern string) EnvMatcher
EnvPattern loads all env vars that match the pattern into the Settings. See path.Match() for match rules.
func EnvPrefix ¶
func EnvPrefix(prefix string) EnvMatcher
EnvPrefix loads all env vars that match the prefix into the Settings. The prefix will be stripped.
type Option ¶
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings stores a tree of settings values, accessed via a path syntax ("path/to/value").
func NewSettings ¶
func (Settings) Bool ¶
Bool answers the bool value at the given path. The value must be a bool, a string (with value "true" or "t") or an element of a slice (for example, if the Settings contains "fruits": ["apple", "orange"], then Bool("fruits/apple") will return true).
func (Settings) Length ¶
Length answers the length of the slice at path, or 0 if path is not a slice.
func (Settings) MustBool ¶
MustBool answers the bool value at the given path or fallback if path is absent.
func (Settings) MustFloat64 ¶
MustFloat64 answers the bool value at the given path or fallback if path is absent.
func (Settings) MustInt64 ¶
MustInt64 answers the bool value at the given path or fallback if path is absent.
func (Settings) MustString ¶
MustString answers the string value at the given path or fallback if path is absent.
func (Settings) SetValue ¶
SetValue sets the given key to the given value. `value` can be nil, and an empty map will be created. Currently the key can not contain a path element; if you want to se a path, find the subset first.
func (Settings) Strings ¶
Strings answers the string slice at the given path. If path points to a string slice, it's returned, otherwise the current keys are returned.
func (Settings) Subset ¶
Subset answers a subset of the settings tree based on walking down the path. The path can have components separated with "/".
func (Settings) WalkKeys ¶
func (s Settings) WalkKeys(fn WalkKeysFunc) error
WalkKeys iterates the keys. You can get the same info from calling Strings(), which is easier to use but less efficient. Not sure that I'll ever need the difference in efficiency though, so this might go away.