appconfig

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 13 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.

README

Per-user application configuration

This package loads typed configuration for the current CLI and v1 daemon. It does not select USB hardware, start a daemon, write library records or move locks.

Select(flagPath, envPath) chooses --config, then NB1_CONFIG, then config.yaml in the shared userconfig.AppDir() directory. It returns absolute paths and a Required marker. It does not create directories. A missing default file uses defaults; a missing explicitly selected file is an error.

The default application directory is:

System Directory
macOS and Linux $XDG_CONFIG_HOME/nb1, or ~/.config/nb1
Windows %AppData%\nb1

Selecting another configuration file does not relocate the default library or ownership directory. Locks remain under the existing native OS application root's device-locks directory; on macOS that is still ~/Library/Application Support/nb1/device-locks. XDG_CONFIG_HOME must be absolute; a relative value is an error even if --config explicitly selects a different file. Older macOS profile/library locations are not aliases or automatically migrated. See configuration and coordination roots before operating a candidate alongside an older daemon.

device: ""
server:
  devices: []
  listen: "127.0.0.1:8931"
jobs:
  terminal_limit: 16384
  terminal_ttl: 30m
library_dir: ""

device is empty or an exact eight-digit hexadecimal serial string. Quote numeric-looking serials. server.devices contains up to 64 distinct serial strings; it does not discover connected devices. server.listen must use a loopback IP or localhost and a numeric port in 0–65535. Service installation can impose a nonzero-port requirement separately.

Both Job limits must be positive. terminal_ttl is a Go duration string, such as 30m or 1h30m, measured from terminal publication. It is a maximum retention duration: the count limit can evict terminal Jobs sooner. Daemon restart also discards Jobs. An evicted ID can be accepted and executed again; these settings do not promise a guaranteed deduplication window.

An empty library_dir uses the stable application directory's library subdirectory. An override must be absolute. The existing libraryv1 store owns colors/ and patterns/; loading this configuration does not create either.

Load(selection) starts from Defaults(selection.BaseDir) and rejects malformed YAML, unknown fields, duplicate keys, aliases, merges, incorrect scalar types, multiple documents and invalid settings. Files must be regular, not symlinks or FIFOs, and at most 1 MiB; reads are bounded. The original setting.yaml fields title, base_url, port, content_dir and color are accepted as opaque YAML for the existing Viper commands, but are excluded from the typed Config output. No recent experimental configuration fields are recognized. NB1_DEVICE remains the responsibility of the existing CLI integration; nested environment variables are not automatically imported here.

Template() supplies a documented example without a selected device. Init(path) explicitly creates its private parent directory and a new 0600 file, refuses existing files, and creates no library directory. Existing parent permissions are never changed. On Windows, directory ACLs are inherited rather than represented by POSIX mode bits.

Verification: go test -race ./internal/appconfig.

Documentation

Overview

Package appconfig reads the current CLI and daemon's per-user configuration. Loading configuration never creates directories, scans USB or starts a service.

Index

Constants

View Source
const (
	Filename             = "config.yaml"
	MaxFileBytes         = 1 << 20
	DefaultTerminalLimit = 16384
	DefaultTerminalTTL   = 30 * time.Minute
	DefaultListen        = "127.0.0.1:8931"
)

Variables

This section is empty.

Functions

func DefaultBaseDir

func DefaultBaseDir() (string, error)

func Init

func Init(path string) error

Init explicitly creates a private configuration directory and a new 0600 example file. Existing files are never replaced; library directories are not created. Existing parent directory permissions are checked, never changed.

func Template

func Template() []byte

Template returns a documented configuration with no selected hardware.

func Validate

func Validate(config Config) error

Types

type Config

type Config struct {
	Device     string       `json:"device" yaml:"device"`
	Server     ServerConfig `json:"server" yaml:"server"`
	Jobs       JobConfig    `json:"jobs" yaml:"jobs"`
	LibraryDir string       `json:"library_dir" yaml:"library_dir"`
}

func Defaults

func Defaults(baseDir string) Config

func Load

func Load(selected Selection) (Config, error)

Load reads at most MaxFileBytes+1 bytes. Only a missing optional default file is ignored. A configured but unreadable, malformed or invalid file is an error.

type JobConfig

type JobConfig struct {
	TerminalLimit int           `json:"terminal_limit" yaml:"terminal_limit"`
	TerminalTTL   time.Duration `json:"terminal_ttl" yaml:"terminal_ttl"`
}

type Selection

type Selection struct {
	BaseDir  string
	Path     string
	Required bool
}

Selection separates the stable application storage root from the selected configuration file. Choosing another file does not relocate libraries or locks.

func Select

func Select(flagPath, envPath string) (Selection, error)

Select implements --config > NB1_CONFIG > the user's nb1/config.yaml. Callers pass the flag and environment values explicitly; no environment is otherwise imported into typed configuration.

type ServerConfig

type ServerConfig struct {
	Devices []string `json:"devices" yaml:"devices"`
	Listen  string   `json:"listen" yaml:"listen"`
}

Jump to

Keyboard shortcuts

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