config

package
v1.1.35 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 8 Imported by: 0

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

View Source
var DefaultThresholds = []int{40, 60, 100}

DefaultThresholds is the default tripwire list applied when no user config exists.

View Source
var ErrInvalidThresholds = errors.New("invalid thresholds")

ErrInvalidThresholds is returned when a threshold list fails validation rules.

Functions

func DefaultPath

func DefaultPath() (string, error)

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

func FormatThresholds(ts []int) string

FormatThresholds renders a threshold list back to the canonical comma-separated form.

func ParseThresholds

func ParseThresholds(s string) ([]int, error)

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

func Save(path string, c Config) error

Save writes c to path, creating the parent directory at 0700 and the file at 0600 if needed. Validation runs first.

func ValidateThresholds

func ValidateThresholds(ts []int) error

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

func Load(path string) (Config, error)

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

func (c Config) CooldownDuration() time.Duration

CooldownDuration returns the auto-switch cool-down as a time.Duration.

func (Config) Validate

func (c Config) Validate() error

Validate enforces invariants on c. Used by both Load and Save so we fail fast on bad on-disk state and refuse to persist bad in-memory state.

Jump to

Keyboard shortcuts

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