config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 10 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 config owns ChannelTerm's persisted connection configuration, connection policy, and user preferences.

Configuration is intentionally separate from transports and Sessions. The application layer translates a resolved connection profile into the concrete transport configuration it needs; user preferences never take part in that translation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrProfileNotFound is returned when a named serial profile does not exist.
	ErrProfileNotFound = errors.New("serial profile not found")
	// ErrSerialPortRequired is returned when the final serial settings have no port.
	ErrSerialPortRequired = errors.New("serial port is required")
)

Functions

func DefaultHTTPAuthTokenPath

func DefaultHTTPAuthTokenPath() (string, error)

DefaultHTTPAuthTokenPath returns the per-user credential path used by the local Streamable HTTP Host and ChannelTerm's built-in HTTP clients.

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the platform's normal location for config.toml.

The path is based on os.UserConfigDir, which uses the appropriate Windows or Unix user configuration directory. It does not create files or directories.

func DefaultStatePath

func DefaultStatePath() (string, error)

DefaultStatePath returns the platform's normal location for state.json.

State is kept beside the user configuration but has a separate lifecycle: it is maintained by ChannelTerm to retain discovered device identities and must never be treated as user connection configuration.

func LoadOrCreateHTTPAuthToken

func LoadOrCreateHTTPAuthToken(path string) (string, error)

LoadOrCreateHTTPAuthToken returns a stable random bearer token from path. Creation is serialized across processes and installs only a complete 32-byte Base64URL credential. New files use owner-only permissions where the operating system honors them.

func RequireSerialPort

func RequireSerialPort(profile SerialProfile) error

RequireSerialPort returns an error when profile does not name a serial port.

func Save

func Save(path string, file File) error

Save writes file as TOML to path, creating its parent directory if needed.

It persists all populated File sections through their shared config.toml lifecycle. An empty Preferences value is omitted, so saving a serial profile does not add an empty preferences table.

func Update

func Update(path string, update func(*File) error) error

Update serializes one read-modify-write transaction across ChannelTerm processes. update receives the latest on-disk value while an adjacent lock file is held; returning an error leaves the configuration unchanged.

Types

type Connection

type Connection struct {
	DefaultPolicy string `toml:"default_policy,omitempty"`
}

Connection contains global behavior for clients reacting to device discovery.

DefaultPolicy does not identify a device and never authorizes or prevents an explicit user-requested connection. It controls only the default reaction to a newly discovered endpoint.

type File

type File struct {
	Serial      Serial      `toml:"serial"`
	Connection  Connection  `toml:"connection"`
	Preferences Preferences `toml:"preferences,omitempty"`
}

File is the complete ChannelTerm configuration file.

Serial stores connection profiles, Connection stores discovery policy, and Preferences stores adapter-local user preferences. All three share one config.toml lifecycle, while their responsibilities remain independent.

Preferences is omitted from TOML until it contains persisted fields, so adding this boundary does not rewrite existing configuration into a new schema section.

func Load

func Load(path string) (File, error)

Load reads and decodes a TOML configuration file at path.

It begins with DefaultPreferences so fields added in future releases can default correctly when absent from an existing config.toml. It validates the connection discovery policy but leaves serial value validation to the serial opening boundary, preserving the existing resolution lifecycle.

func LoadOrCreate

func LoadOrCreate(path string) (File, error)

LoadOrCreate loads a TOML configuration file, creating the minimal template when it does not exist. Existing configuration files are read only.

The template intentionally contains no preferences section because the current Preferences model has no persisted fields.

func (File) ConnectionPolicy

func (file File) ConnectionPolicy() (connectionpolicy.Policy, error)

ConnectionPolicy resolves the configured default discovery policy.

An omitted default_policy resolves to ask. Any non-empty unsupported value returns a clear validation error so callers never silently fall back to a different discovery behavior.

func (File) ResolveSerial

func (file File) ResolveSerial(name string) (SerialProfile, error)

ResolveSerial selects a named profile, or the configured default when name is empty, and applies built-in serial defaults to omitted profile fields.

With neither a requested nor configured name, it returns only the built-in serial defaults. It reads only Serial and never consults Preferences.

func (*File) SaveSerialProfile

func (file *File) SaveSerialProfile(name string, profile SerialProfile)

SaveSerialProfile stores a resolved serial profile under name.

It initializes the profile map when necessary and selects name as the default only when no default profile is configured. It preserves name exactly so established --save profile-key behavior remains unchanged. It changes only the connection-profile portion of File; callers persist the result with Save.

type Preferences

type Preferences struct{}

Preferences contains user-owned presentation preferences.

It deliberately has no fields yet. Future terminal-display, UI, TUI, and GUI preferences belong here, are loaded and saved through File, and must not affect connection profile resolution or Transport construction. Its empty value is omitted from TOML, preserving existing config.toml output until a concrete preference is introduced.

func DefaultPreferences

func DefaultPreferences() Preferences

DefaultPreferences returns the default user preferences.

The current model has no configurable values. Keeping a constructor makes defaults explicit at the configuration boundary: Load starts from this value before decoding TOML, so later defaulted fields can remain absent from older configuration files.

type Serial

type Serial struct {
	Default  string                   `toml:"default,omitempty"`
	Profiles map[string]SerialProfile `toml:"profiles,omitempty"`
}

Serial contains named serial connection profiles and an optional default.

It is connection configuration only. It does not contain presentation preferences or own a live serial Transport.

type SerialOverrides

type SerialOverrides struct {
	Port        *string
	BaudRate    *int
	DataBits    *int
	Parity      *string
	StopBits    *string
	FlowControl *string
	Wake        *bool
}

SerialOverrides represents serial values explicitly supplied by an adapter. Nil fields leave the resolved profile unchanged, preserving the distinction between an omitted CLI flag or MCP property and one set to its default value.

type SerialProfile

type SerialProfile struct {
	Port        string `toml:"port,omitempty"`
	BaudRate    int    `toml:"baud,omitempty"`
	DataBits    int    `toml:"data_bits,omitempty"`
	Parity      string `toml:"parity,omitempty"`
	StopBits    string `toml:"stop_bits,omitempty"`
	FlowControl string `toml:"flow_control,omitempty"`
	Wake        bool   `toml:"wake"`
}

SerialProfile contains serial connection settings stored in a named profile.

Empty numeric and string fields inherit the built-in conventional settings when the profile is resolved. Wake is false unless explicitly enabled.

func ApplySerialOverrides

func ApplySerialOverrides(profile SerialProfile, overrides SerialOverrides) SerialProfile

ApplySerialOverrides applies explicitly supplied adapter settings to profile.

Jump to

Keyboard shortcuts

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