settings

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeReadWrite = "readwrite"
	ModeReadOnly  = "read"
	ModeWriteOnly = "write"
)

Reader mode identifiers as they appear on the wire and on disk. nfc's ReaderMode is an iota, so persisting it directly would reinterpret stored files if a mode were ever inserted.

Variables

This section is empty.

Functions

func FormatMode

func FormatMode(mode nfc.ReaderMode) string

FormatMode converts a nfc.ReaderMode to its stored identifier.

func ParseMode

func ParseMode(mode string) nfc.ReaderMode

ParseMode converts a stored identifier to a nfc.ReaderMode, falling back to read/write so a file from a newer build cannot leave the reader unusable.

Types

type Settings

type Settings struct {
	// Mode is the reader access mode: "readwrite", "read" or "write".
	Mode string `json:"mode"`

	// CardTypes is the card-type allowlist. Empty means every type is allowed,
	// matching the agent's behaviour when no filter has ever been set.
	CardTypes []string `json:"cardTypes"`

	// DevicePath pins a specific reader. Empty means auto-detect.
	DevicePath string `json:"devicePath"`

	// Port is the agent server port. Zero means the built-in default.
	//
	// Applied at startup only: changing it needs the listener rebound, which
	// the console does explicitly rather than as a side effect of saving.
	Port int `json:"port"`

	// RequirePairedDevice admits only devices holding a paired credential.
	RequirePairedDevice bool `json:"requirePairedDevice"`
}

Settings holds the operator preferences that survive a restart.

Credentials are deliberately not here: the API secret, paired devices and origin allowlist keep their own files.

func Defaults

func Defaults() Settings

Defaults are what the agent does when no file has ever been saved.

type Store

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

Store persists Settings under the config directory.

func New

func New(configDir string) (*Store, error)

New loads settings from configDir, falling back to the defaults. No file is written on load, so its absence keeps meaning "never configured". An empty configDir yields an in-memory store.

func (*Store) Get

func (s *Store) Get() Settings

Get returns the current settings.

func (*Store) OnChange

func (s *Store) OnChange(fn func(Settings))

OnChange registers a callback fired whenever the settings change.

func (*Store) Path

func (s *Store) Path() string

Path returns the settings file location, or "" for an in-memory store.

func (*Store) Save

func (s *Store) Save(next Settings) error

Save replaces the settings and persists them, normalizing first.

func (*Store) Update

func (s *Store) Update(mutate func(*Settings)) (Settings, error)

Update applies a mutation and persists the result, without the caller having to read-modify-write around the lock.

Jump to

Keyboard shortcuts

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