Documentation
¶
Overview ¶
Package appsettings provides simple key/value store functionality designed to be used for easily storing and recalling application runtime settings
Index ¶
- Variables
- func OptionPrettyPrint(app *AppSettings)
- type AppSettings
- func (a AppSettings) DecrInt64(key string) int64
- func (a AppSettings) Delete(key string)
- func (a AppSettings) DeleteTree(key string)
- func (a AppSettings) GetInt(key string) (int, error)
- func (a AppSettings) GetInt64(key string) (int64, error)
- func (a AppSettings) GetLeaves() map[string]string
- func (a AppSettings) GetString(key string) (string, error)
- func (a AppSettings) GetTree(key string) DataTree
- func (a AppSettings) GetTrees() map[string]DataTree
- func (a AppSettings) HasLeaf(key string) bool
- func (a AppSettings) HasTree(key string) bool
- func (a AppSettings) IncrInt64(key string) int64
- func (a *AppSettings) Persist() error
- func (a AppSettings) SetInt(key string, val int)
- func (a AppSettings) SetInt64(key string, val int64)
- func (a AppSettings) SetString(key string, val string)
- type DataTree
- type Option
Constants ¶
This section is empty.
Variables ¶
var ErrUndefinedKey = errors.New("undefined key")
ErrUndefinedKey is returned when the key requested from get is undefined.
Functions ¶
func OptionPrettyPrint ¶ added in v0.3.0
func OptionPrettyPrint(app *AppSettings)
OptionPrettyPrint configures AppSettings to pretty print the saved json
Types ¶
type AppSettings ¶
type AppSettings struct {
// contains filtered or unexported fields
}
AppSettings is the root most DataTree
func NewAppSettings ¶
func NewAppSettings(dbFilename string, options ...Option) (*AppSettings, error)
NewAppSettings gets a new AppSettings struct
func (AppSettings) DecrInt64 ¶ added in v0.4.0
DecrInt64 decrements an int or int64 leaf and returns the new value as int64.
If the key is undefined or non-integer, this will initialize it to 0 and decrements it to -1
func (AppSettings) Delete ¶ added in v0.1.0
func (a AppSettings) Delete(key string)
Delete removes the given leaf from the branch.
func (AppSettings) DeleteTree ¶ added in v0.2.0
func (a AppSettings) DeleteTree(key string)
DeleteTree removes the given tree from the branch.
func (AppSettings) GetInt ¶ added in v0.1.0
GetInt gets the give keys leaf as an int.
Returns an ErrUndefinedKey if the key is not defined.
Will return an error if ParseInt of the value of the leaf fails.
func (AppSettings) GetInt64 ¶ added in v0.1.0
GetInt64 gets the give keys leaf as an int64.
Returns an ErrUndefinedKey if the key is not defined.
Will return an error if ParseInt(...,10, 64) of the value of the leaf fails.
func (AppSettings) GetString ¶ added in v0.1.0
GetString gets the give keys leaf as a string.
Returns an ErrUndefinedKey if the key is not defined
func (AppSettings) HasLeaf ¶ added in v0.3.0
HasLeaf checks if the given key is defined as a leaf value
func (AppSettings) IncrInt64 ¶ added in v0.4.0
IncrInt64 increments an int or int64 leaf and returns the new value as int64.
If the key is undefined or non-integer, this will initialize it to 0 and increment it to 1
func (*AppSettings) Persist ¶
func (a *AppSettings) Persist() error
Persist causes the current state of the app settings to be persisted.
type DataTree ¶
type DataTree interface { GetString(key string) (string, error) SetString(key string, val string) GetInt(key string) (int, error) SetInt(key string, val int) GetInt64(key string) (int64, error) SetInt64(key string, val int64) IncrInt64(key string) int64 DecrInt64(key string) int64 Delete(key string) DeleteTree(key string) GetTree(key string) DataTree HasTree(key string) bool HasLeaf(key string) bool GetTrees() map[string]DataTree GetLeaves() map[string]string }
DataTree is the host of key and branches of values
type Option ¶ added in v0.3.0
type Option func(*AppSettings)
Option sets an option of the passed AppSettings