-
Luan Duarte authored037c3481
Go implementation of the XDG Base Directory Specification and XDG user directories.
Provides an implementation of the XDG Base Directory Specification. The specification defines a set of standard paths for storing application files, including data and configuration files. For portability and flexibility reasons, applications should use the XDG defined locations instead of hardcoding paths.
The package also includes the locations of well known user directories,
support for the non-standard XDG_BIN_HOME
directory, as well as other common directories such as fonts and applications.
The current implementation supports most flavors of Unix, Windows, macOS and Plan 9.
On Windows, where XDG environment variables are not usually set, the package uses Known Folders
as defaults. Therefore, appropriate locations are used for common folders which may have been redirected.
See usage examples below. Full documentation can be found at https://pkg.go.dev/github.com/adrg/xdg.
Installation
go get github.com/adrg/xdg
Default locations
The package defines sensible defaults for XDG variables which are empty or not present in the environment.
- On Unix-like operating systems, XDG environment variables are typically defined. Appropriate default locations are used for the environment variables which are not set.
- On Windows, XDG environment variables are usually not set. If that is the case, the package relies on the appropriate Known Folders. Sensible fallback locations are used for the folders which are not set.
XDG Base Directory
Unix-like operating systems
Microsoft Windows
XDG user directories
XDG user directories environment variables are usually not set on most operating systems. However, if they are present in the environment, they take precedence. Appropriate fallback locations are used for the environment variables which are not set.
- On Unix-like operating systems (except macOS and Plan 9), the package reads the user-dirs.dirs config file.
- On Windows, the package uses the appropriate Known Folders.
Lastly, default locations are used for any user directories which are not set, as shown in the following tables.