Documentation
¶
Overview ¶
Package settings keeps small values that outlive the app - settings, progress, the last opened file - as JSON in the app's data directory (the browser's local storage on the web). It's for plain data: keep secrets in giode.SecureStore.
settings.Save("theme", "dark")
theme := settings.Value("theme", "light")
// A State that loads on start and saves itself on every change:
progress := settings.Bind("progress", map[string]bool{})
progress.Update(func(p map[string]bool) map[string]bool { p["orbits"] = true; return p })
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Default = &Store{backend: defaultBackend()}
Default is the app's store: settings.json in the app's data directory (its own folder under the user's config directory on desktops, the app's private files on Android and iOS), or the browser's local storage on the web.
var ErrNoStorage = errors.New("settings: no storage on this platform")
ErrNoStorage is returned when the platform has nowhere to keep settings.
Functions ¶
func Bind ¶
Bind returns a State holding the value saved under key in the Default store (initial when there's none) that saves itself every time it changes. Make it once, as a package-level var or beside the component that uses it.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a set of named values kept as one JSON document. Its methods may be called from any goroutine. Changes are written at once, the whole document replaced atomically, so a crash never leaves it half written.
func (*Store) Get ¶
Get decodes the value stored under key into v, a pointer, and reports whether there was one that decoded.