userconfig

package
v0.8.10 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package userconfig persists per-machine user preferences for the system tray (auto-start toggles, default project, self-update state) in a single JSON file under a hidden app directory in the user's home.

One installed binary = one config file. The directory is named after the running binary, so a user who installs the same app under two different names ("wick-manager", "client-tools") gets two separate configs without collision.

Path:

~/.<binary>/config.json

Settings here are machine-wide, not per-project. Per-project state (e.g., wick app data) still lives in the project's wick.db when launched from a project directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir added in v0.8.9

func Dir(name string) (string, error)

Dir returns the absolute per-app data directory. Empty name falls back to the running binary's basename.

func Path

func Path(name string) (string, error)

Path returns the absolute config file path for the given project name. Empty name falls back to the running binary's basename.

func ResolveDBPath

func ResolveDBPath(appName, customPath string)

ResolveDBPath determines the SQLite DB path and sets DATABASE_URL so config.Load() picks it up wherever it is called next.

Resolution order (first non-empty wins, never overwrites a higher priority):

  1. DATABASE_URL env already set (explicit env / CI override) → untouched
  2. cfg.DatabasePath set (user edited database_path in config.json)
  3. <binary_dir>/wick.db when wick.yml exists next to the binary (project mode)
  4. ~/.<appName>/wick.db (standalone / downloaded binary)

func ResolvePort

func ResolvePort(customPort int)

ResolvePort sets the PORT env from cfg.Port so config.Load() picks it up wherever it is called next.

Resolution order (first non-empty wins, never overwrites a higher priority):

  1. PORT env already set (explicit env / CI override) → untouched
  2. customPort > 0 (user edited port in config.json)
  3. fall through → env.go envDefault picks the built-in default (9425)

func Save

func Save(name string, cfg Config) error

Save writes the config atomically (write to temp, rename).

Types

type Config

type Config struct {
	// AutoStartApp registers the binary with the OS so it launches at
	// user login (Windows: Run registry, macOS: LaunchAgent plist,
	// Linux: XDG autostart .desktop). Toggle from Preferences ▶ Auto-start app.
	AutoStartApp bool `json:"auto_start_app"`

	// Tray auto-start toggles — applied at the next tray launch.
	AutoStartServer bool `json:"auto_start_server"`
	AutoStartWorker bool `json:"auto_start_worker"`

	// Self-update toggle.
	AutoUpdate bool `json:"auto_update"`

	// Port overrides the HTTP listen port. 0 = use env PORT or default 9425.
	// Set this in config.json to pin a custom port without touching .env.
	Port int `json:"port,omitempty"`

	// LogRetentionDays controls how many days of per-day log files are
	// kept. 0 = use built-in default (7). Set in config.json to override.
	LogRetentionDays int `json:"log_retention_days,omitempty"`

	// DatabasePath overrides the SQLite DB location. Empty = auto-detect.
	// Auto-detect: binary dir has wick.yml → <binary_dir>/wick.db,
	// otherwise ~/.<appName>/wick.db.
	// Set this manually in config.json if you need a custom location.
	DatabasePath string `json:"database_path,omitempty"`

	// Update state — managed by the updater, not user-facing.
	StagedUpdatePath    string `json:"staged_update_path,omitempty"`
	StagedUpdateVersion string `json:"staged_update_version,omitempty"`
}

Config is the on-disk shape. Add fields with `json:"...,omitempty"` so older config files keep working when the binary upgrades.

func Load

func Load(name string) (Config, error)

Load reads the config file for the given project name. Missing file → defaults; parse errors surface to the caller.

Jump to

Keyboard shortcuts

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