appdata

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 6 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 appdata resolves where the application keeps its per-user data: the SQLite database, generated launch scripts, and logs.

The location follows each operating system's convention. The resolver itself is a pure function of the OS name, the home directory, and the environment, so every branch is testable on any host even though only macOS is supported at run time today.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedOS is returned for an operating system with no known data location.
	ErrUnsupportedOS = errors.New("unsupported operating system")

	// ErrNoHomeDir is returned when the home directory is needed but empty.
	ErrNoHomeDir = errors.New("home directory is not set")

	// ErrNoAppDataEnv is returned on Windows when %AppData% is not set.
	ErrNoAppDataEnv = errors.New("APPDATA environment variable is not set")
)

Functions

func Dir

func Dir(goos, home string, getenv func(key string) string) (string, error)

Dir returns the per-user data directory for the given OS, home directory, and environment lookup:

  • darwin: <home>/Library/Application Support/<DataDirName>
  • linux: $XDG_DATA_HOME/<Slug>, else <home>/.local/share/<Slug>
  • windows: %AppData%/<DataDirName>

Any other OS returns ErrUnsupportedOS.

Types

type Paths

type Paths struct {
	Root   string // the per-user data directory
	DB     string // the SQLite database file
	Launch string // generated launch scripts and prompt files
	Logs   string // log files
}

Paths are the application's data locations, all under one root directory.

func NewPaths

func NewPaths(root string) Paths

NewPaths returns the data locations under root.

func Resolve

func Resolve() (Paths, error)

Resolve returns the data locations for the current user on the current OS.

func (Paths) Ensure

func (p Paths) Ensure() error

Ensure creates every data directory that does not exist yet, readable only by the user. Existing directories are left as they are.

Jump to

Keyboard shortcuts

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