A Go library implementing the XDG Base Directory Specification and XDG user directories for portable application file storage.
xdg is a Go library that implements the XDG Base Directory Specification and XDG user directories. It provides a standardized way for applications to store and retrieve configuration, data, cache, and other files across different operating systems, solving the problem of hardcoded, non-portable file paths.
Go developers building command-line tools, desktop applications, or any software that needs to manage user-specific files in a cross-platform manner.
Developers choose xdg because it offers a robust, spec-compliant implementation with zero configuration, automatic fallbacks for unsupported environments, and an intuitive API that simplifies filesystem interactions while ensuring application portability.
Go implementation of the XDG Base Directory Specification and XDG user directories
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically uses environment variables, Windows Known Folders, and config files (e.g., user-dirs.dirs on Unix) to determine paths, with fallbacks for Unix, Windows, macOS, and Plan 9.
Strictly adheres to the XDG Base Directory Specification, including XDG user directories and non-standard extensions like XDG_BIN_HOME, as detailed in the README tables.
Provides helper functions like ConfigFile() and SearchConfigFile() to easily create and locate application files in appropriate directories, reducing boilerplate code.
Supports not only base XDG directories but also fonts, applications, and common user directories, ensuring broad filesystem compatibility.
Relies on system configurations like user-dirs.dirs files on Unix and Windows Known Folders, which can be missing or misconfigured, leading to potential path resolution failures.
As a Go-only package, it doesn't integrate with projects using other programming languages, restricting its utility in polyglot environments.
The README admits that XDG_RUNTIME_DIR might not be available on all systems, and fallbacks like /tmp on Plan 9 or LocalAppData on Windows may not suit all use cases.