settings

package
v1.0.31-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
var ErrNoStorage = errors.New("settings: no storage on this platform")

ErrNoStorage is returned when the platform has nowhere to keep settings.

Functions

func Bind

func Bind[T any](key string, initial T) *state.State[T]

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.

func BindTo

func BindTo[T any](s *Store, key string, initial T) *state.State[T]

BindTo is Bind for another store.

func Delete

func Delete(key string) error

Delete removes key from the Default store.

func Save

func Save(key string, v any) error

Save stores v under key in the Default store.

func Value

func Value[T any](key string, def T) T

Value returns the value stored under key in the Default store, or def when there's none (or it doesn't decode as a T).

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 Open

func Open(path string) *Store

Open returns a store kept in the file at path.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes key and writes the store; a missing key is not an error.

func (*Store) Get

func (s *Store) Get(key string, v any) bool

Get decodes the value stored under key into v, a pointer, and reports whether there was one that decoded.

func (*Store) Has

func (s *Store) Has(key string) bool

Has reports whether a value is stored under key.

func (*Store) Keys

func (s *Store) Keys() []string

Keys returns the stored keys, sorted.

func (*Store) Set

func (s *Store) Set(key string, v any) error

Set stores v, anything encoding/json encodes, under key and writes the store.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL