paths

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 7 Imported by: 1 module, 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 paths resolves the six per-app directories of contract.md section 9.3 on Linux and macOS. Resolution for each: the app's own variable (<APP>_CONFIG_DIR and so on), then the XDG variable, then the platform default. The package does not create the directories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestEnv

func TestEnv(prefix, dir string) []string

TestEnv returns the variables that put every directory of an app under dir, as NAME=value strings for exec.Cmd.Env or t.Setenv: <PREFIX>_CONFIG_DIR=<dir>/config, _DATA_DIR=<dir>/data, _STATE_DIR=<dir>/state, _LOGS_DIR=<dir>/logs, _CACHE_DIR=<dir>/cache, _RUNTIME_DIR=<dir>/run, plus LOG_OUTPUT=stderr so the run writes no log file. prefix is without the trailing underscore ("MYAPP"). It does not clear what the parent environment carries: an inherited <PREFIX>_LOG_OUTPUT wins over LOG_OUTPUT, and OTEL_* and TRACEPARENT would send the run's spans and trace to the real agent; a harness that builds a child environment strips those first.

Types

type Option

type Option func(*resolver)

Option changes how For resolves.

func Prefix

func Prefix(prefix string) Option

Prefix sets the environment prefix without its trailing underscore ("MYAPP"), the form identity.Prefix takes, when it differs from the one derived from the app name: paths.For(id.Name, paths.Prefix(id.Prefix)). Empty keeps the derived prefix. A prefix with a trailing underscore is a programming error and panics, so "MYAPP_" cannot read MYAPP__CONFIG_DIR silently.

type Paths

type Paths struct {
	// Config holds settings and secrets; it moves with the user to a new machine.
	Config string
	// Data holds what the app cannot regenerate; it moves with the user.
	Data string
	// State holds what the app rebuilds over time; it stays on the machine.
	State string
	// Logs holds the log files of contract.md section 5.
	Logs string
	// Cache holds what the app can refetch.
	Cache string
	// Runtime holds sockets, pid and lock files; cleared at logout or reboot.
	Runtime string
}

Paths holds the six directories of one app.

func For

func For(app string, opts ...Option) Paths

For returns the directories of app.

Jump to

Keyboard shortcuts

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