xdg

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 7 Imported by: ? 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 xdg resolves the XDG base directories and user directories: the base directories themselves, and an app's own directory under each, all read from an Env.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env func(name string) string

Env is the environment the directories are resolved from: it maps a variable's name to its value, "" when unset, as os.Getenv does. Tests pass their own to leave the process environment alone.

var OS Env = os.Getenv

OS is the process environment.

func (Env) CacheDir

func (e Env) CacheDir(app string) (string, bool)

CacheDir is app's cache directory, $XDG_CACHE_HOME/app or ~/.cache/app; false when neither variable holds an absolute path. It panics on an app that is not a single path element.

func (Env) CacheHome

func (e Env) CacheHome() (string, bool)

CacheHome is the user's cache directory itself, $XDG_CACHE_HOME or ~/.cache, where caches shared across apps live (the thumbnails); false when neither variable holds an absolute path.

func (Env) ConfigDir

func (e Env) ConfigDir(app string) (string, bool)

ConfigDir is app's configuration directory, $XDG_CONFIG_HOME/app or ~/.config/app; false when neither variable holds an absolute path. It panics on an app that is not a single path element.

func (Env) ConfigDirs

func (e Env) ConfigDirs() []string

ConfigDirs are the system configuration directories, most important first: the absolute entries of $XDG_CONFIG_DIRS, or /etc/xdg when it names none.

func (Env) ConfigHome

func (e Env) ConfigHome() (string, bool)

ConfigHome is the user's configuration directory itself, $XDG_CONFIG_HOME or ~/.config, where configuration shared across apps lives (user-dirs.dirs); false when neither variable holds an absolute path.

func (Env) DataDir

func (e Env) DataDir(app string) (string, bool)

DataDir is app's data directory, $XDG_DATA_HOME/app or ~/.local/share/app; false when neither variable holds an absolute path. It panics on an app that is not a single path element.

func (Env) DataHome

func (e Env) DataHome() (string, bool)

DataHome is the user's data directory itself, $XDG_DATA_HOME or ~/.local/share, where data shared across apps lives (the trash, the recently-used list); false when neither variable holds an absolute path.

func (Env) RuntimeDir

func (e Env) RuntimeDir(app string) (string, bool)

RuntimeDir is app's runtime directory, $XDG_RUNTIME_DIR/app, for sockets and markers that live as long as the login; false when the variable holds no absolute path, as the spec defines no fallback. It panics on an app that is not a single path element.

func (Env) RuntimeHome

func (e Env) RuntimeHome() (string, bool)

RuntimeHome is the user's runtime directory itself, $XDG_RUNTIME_DIR; false when it holds no absolute path.

func (Env) StateDir

func (e Env) StateDir(app string) (string, bool)

StateDir is app's state directory, $XDG_STATE_HOME/app or ~/.local/state/app; false when neither variable holds an absolute path. It panics on an app that is not a single path element.

func (Env) UserDir

func (e Env) UserDir(key string) (string, bool, error)

UserDir is a user directory from $XDG_CONFIG_HOME/user-dirs.dirs (glib's g_get_user_special_dir): key is the name between XDG_ and _DIR (DOCUMENTS, PICTURES, ...), the value's leading $HOME expanded. It is not set, false with a nil error, when there is no config directory, no user-dirs.dirs or no line for key. Every other failure is an error: the file could not be read, or key's value is not a quoted absolute or $HOME-relative path.

Jump to

Keyboard shortcuts

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