settings

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package settings stores plugin options declared with plugin.SettingsSpec. Values live in data/<plugin>/settings.json; the companion bot edits them.

Index

Constants

View Source
const FileName = "settings.json"

FileName is the per-plugin settings file inside data/<plugin>/.

Variables

This section is empty.

Functions

func Validate

func Validate(spec *plugin.SettingsSpec) error

Validate checks a spec before it is registered.

Types

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds every registered settings spec.

func NewRegistry

func NewRegistry(root string) *Registry

NewRegistry keeps settings under root/<plugin>/settings.json.

func (*Registry) Get

func (r *Registry) Get(name string) (*Store, bool)

Get returns a plugin's store.

func (*Registry) Names

func (r *Registry) Names() []string

Names lists plugins with settings, sorted.

func (*Registry) Register

func (r *Registry) Register(spec *plugin.SettingsSpec) (*Store, error)

Register validates spec, loads saved values and returns the store. A plugin registers once per load; unloading it frees the name again.

func (*Registry) Unregister

func (r *Registry) Unregister(name string)

Unregister drops a plugin's spec. Saved values stay on disk.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is one plugin's settings. It implements plugin.Settings.

func (*Store) Bool

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

func (*Store) Get

func (s *Store) Get(key string) any

Get returns the value of key or its default.

func (*Store) Int

func (s *Store) Int(key string) int

func (*Store) IsDefault

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

IsDefault reports whether key still has its default value.

func (*Store) Reset

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

Reset restores the default value.

func (*Store) Set

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

Set stores a value of the setting's type and runs OnChange.

func (*Store) SetText

func (s *Store) SetText(key, text string) error

SetText parses typed text for a text or number setting, runs Validate and stores it. The error text is meant for the owner.

func (*Store) Setting

func (s *Store) Setting(key string) (*plugin.Setting, bool)

Setting returns the declaration of key.

func (*Store) Spec

func (s *Store) Spec() *plugin.SettingsSpec

Spec returns the declared spec.

func (*Store) String

func (s *Store) String(key string) string

Jump to

Keyboard shortcuts

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