Documentation
¶
Overview ¶
Package config holds aimonitor's user-facing configuration: thresholds for the auto-switch tripwires, autoswitch on/off, cool-down, etc. Values live on disk in a YAML file at the platform's XDG config dir; this package validates and parses them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultThresholds = []int{40, 60, 100}
DefaultThresholds is the default tripwire list applied when no user config exists.
var ErrInvalidThresholds = errors.New("invalid thresholds")
ErrInvalidThresholds is returned when a threshold list fails validation rules.
Functions ¶
func DefaultPath ¶
DefaultPath returns the platform-appropriate config-file location.
- $XDG_CONFIG_HOME/aimonitor/config.yaml when XDG_CONFIG_HOME is set.
- ~/.config/aimonitor/config.yaml otherwise (works on both macOS and Linux).
func FormatThresholds ¶
FormatThresholds renders a threshold list back to the canonical comma-separated form.
func ParseThresholds ¶
ParseThresholds parses a comma-separated list (e.g. "40,60,100") and validates it. Whitespace around values is ignored. An empty string is invalid.
func Save ¶
Save writes c to path, creating the parent directory at 0700 and the file at 0600 if needed. Validation runs first.
func ValidateThresholds ¶
ValidateThresholds enforces:
- at least one value
- all values in the range (0, 100]
- strictly ascending (no duplicates, no decreases)
Types ¶
type Config ¶
type Config struct {
// AutoSwitch enables the auto-switch engine. Default false — users
// opt in only after they've tested manual switch and trust the
// probe-gated decisions.
AutoSwitch bool `yaml:"autoswitch"`
// Thresholds is the ascending-int tripwire list (see thresholds.go
// for validation rules). Default [40, 60, 100].
Thresholds []int `yaml:"thresholds"`
// AutoSwitchCooldownSeconds is the minimum gap between two auto-switch
// decisions. Prevents thrashing.
AutoSwitchCooldownSeconds int `yaml:"autoswitch_cooldown_seconds"`
// AutoStart toggles the OS-level autostart (LaunchAgent on macOS,
// systemd --user unit on Linux). This is a hint — actual install/
// uninstall of the unit happens in the install package.
AutoStart bool `yaml:"autostart"`
}
Config is the on-disk shape of aimonitor's user config. YAML tags use snake_case to match conventional dotfile conventions.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the config aimonitor starts with on a fresh install. Used by Load() when the YAML file is missing.
func Load ¶
Load reads the YAML at path and returns a validated Config. When the file does not exist, returns DefaultConfig() (no error). When the file exists but is malformed, returns the parse error so the caller can surface it instead of silently masking a broken config.
The returned Config has gone through validation: Thresholds must be a valid ascending list, cooldown must be non-negative.
func (Config) CooldownDuration ¶
CooldownDuration returns the auto-switch cool-down as a time.Duration.