Description
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.
Full documentation can be found at: https://godoc.org/github.com/adrg/xdg
xdg-go alternatives and similar packages
Based on the "Go Tools" category.
Alternatively, view xdg-go alternatives based on common mentions on social networks and blogs.
-
JuiceFS
JuiceFS is a distributed POSIX file system built on top of Redis and S3. -
JSON-to-Go
Translates JSON into a Go type in your browser instantly (original) -
The Go Play Space
Advanced Go Playground frontend written in Go, with syntax highlighting, turtle graphics mode, and more -
Peanut
๐บ Deploy Databases and Services Easily for Development and Testing Pipelines. -
golang-tutorials
Golang Tutorials. Learn Golang from Scratch with simple examples. -
typex
[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations. -
golang-ipc
Golang Inter-process communication library for Window, Mac and Linux. -
gothanks
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself. -
Viney's go-cache
A flexible multi-layer Go caching library to deal with in-memory and shared cache by adopting Cache-Aside pattern. -
go-lock
go-lock is a lock library implementing read-write mutex and read-write trylock without starvation -
goroutines
It is an efficient, flexible, and lightweight goroutine pool. It provides an easy way to deal with concurrent tasks with limited resource. -
gotestdox
A tool for formatting Go test results as readable documentation -
PDF to Image Converter Using Golang
This project will help you to convert PDF file to IMAGE using golang. -
An exit strategy for go routines.
An exit strategy for go routines -
import "github/shuLhan/share"
A collection of libraries and tools written in Go; including DNS, email, git ini file format, HTTP, memfs (embedding file into Go), paseto, SMTP, TOTP, WebSocket, XMLRPC, and many more. -
go-james
James is your butler and helps you to create, build, debug, test and run your Go projects -
generator-go-lang
A Yeoman generator to get new Go projects started. -
go-sanitize
:bathtub: Golang library of simple to use sanitation functions -
docs
Automatically generate RESTful API documentation for GO projects - aligned with Open API Specification standard -
gomodrun
The forgotten go tool that executes and caches binaries included in go.mod files. -
go-whatsonchain
:link: Unofficial golang implementation for the WhatsOnChain API -
channelize
A websocket framework to manage outbound streams. Allowing to have multiple channels per connection that includes public and private channels. -
Proofable
General purpose proving framework for certifying digital assets to public blockchains -
redispubsub
Redis Streams queue driver for https://godoc.org/gocloud.dev/pubsub package -
go-slices
Helper functions for the manipulation of slices of all types in Go -
MessageBus implementation for CQRS projects
CQRS Implementation for Golang language
Clean code begins in your IDE with SonarLint
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of xdg-go or a related project?
README
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, 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
Unix | macOS | Plan 9 | |
---|---|---|---|
XDG_DATA_HOME | ~/.local/share | ~/Library/Application Support | $home/lib |
XDG_DATA_DIRS | /usr/local/share/usr/share | /Library/Application Support | /lib |
XDG_CONFIG_HOME | ~/.config | ~/Library/Application Support | $home/lib |
XDG_CONFIG_DIRS | /etc/xdg | ~/Library/Preferences/Library/Application Support/Library/Preferences | /lib |
XDG_STATE_HOME | ~/.local/state | ~/Library/Application Support | $home/lib/state |
XDG_CACHE_HOME | ~/.cache | ~/Library/Caches | $home/lib/cache |
XDG_RUNTIME_DIR | /run/user/UID | ~/Library/Application Support | /tmp |
Microsoft Windows
Known Folder(s) | Fallback(s) | |
---|---|---|
XDG_DATA_HOME | LocalAppData | %LOCALAPPDATA% |
XDG_DATA_DIRS | RoamingAppDataProgramData | %APPADATA%%ProgramData% |
XDG_CONFIG_HOME | LocalAppData | %LOCALAPPDATA% |
XDG_CONFIG_DIRS | ProgramDataRoamingAppData | %ProgramData%%APPDATA% |
XDG_STATE_HOME | LocalAppData | %LOCALAPPDATA% |
XDG_CACHE_HOME | LocalAppData\cache | %LOCALAPPDATA%\cache |
XDG_RUNTIME_DIR | LocalAppData | %LOCALAPPDATA% |
XDG user directories
Unix-like operating systems
Unix | macOS | Plan 9 | |
---|---|---|---|
XDG_DESKTOP_DIR | ~/Desktop | ~/Desktop | $home/desktop |
XDG_DOWNLOAD_DIR | ~/Downloads | ~/Downloads | $home/downloads |
XDG_DOCUMENTS_DIR | ~/Documents | ~/Documents | $home/documents |
XDG_MUSIC_DIR | ~/Music | ~/Music | $home/music |
XDG_PICTURES_DIR | ~/Pictures | ~/Pictures | $home/pictures |
XDG_VIDEOS_DIR | ~/Videos | ~/Movies | $home/videos |
XDG_TEMPLATES_DIR | ~/Templates | ~/Templates | $home/templates |
XDG_PUBLICSHARE_DIR | ~/Public | ~/Public | $home/public |
Microsoft Windows
Known Folder(s) | Fallback(s) | |
---|---|---|
XDG_DESKTOP_DIR | Desktop | %USERPROFILE%\Desktop |
XDG_DOWNLOAD_DIR | Downloads | %USERPROFILE%\Downloads |
XDG_DOCUMENTS_DIR | Documents | %USERPROFILE%\Documents |
XDG_MUSIC_DIR | Music | %USERPROFILE%\Music |
XDG_PICTURES_DIR | Pictures | %USERPROFILE%\Pictures |
XDG_VIDEOS_DIR | Videos | %USERPROFILE%\Videos |
XDG_TEMPLATES_DIR | Templates | %APPDATA%\Microsoft\Windows\Templates |
XDG_PUBLICSHARE_DIR | Public | %PUBLIC% |
Other directories
Unix-like operating systems
Unix | macOS | Plan 9 | |
---|---|---|---|
Home | $HOME | $HOME | $home |
Applications | $XDG_DATA_HOME/applications~/.local/share/applications/usr/local/share/applications/usr/share/applications$XDG_DATA_DIRS/applications | /Applications | $home/bin/bin |
Fonts | $XDG_DATA_HOME/fonts~/.fonts~/.local/share/fonts/usr/local/share/fonts/usr/share/fonts$XDG_DATA_DIRS/fonts | ~/Library/Fonts/Library/Fonts/System/Library/Fonts/Network/Library/Fonts | $home/lib/font/lib/font |
Microsoft Windows
Known Folder(s) | Fallback(s) | |
---|---|---|
Home | Profile | %USERPROFILE% |
Applications | ProgramsCommonPrograms | %APPDATA%\Microsoft\Windows\Start Menu\Programs%ProgramData%\Microsoft\Windows\Start Menu\Programs |
Fonts | Fonts- | %SystemRoot%\Fonts%LOCALAPPDATA%\Microsoft\Windows\Fonts |
Usage
XDG Base Directory
package main
import (
"log"
"github.com/adrg/xdg"
)
func main() {
// XDG Base Directory paths.
log.Println("Home data directory:", xdg.DataHome)
log.Println("Data directories:", xdg.DataDirs)
log.Println("Home config directory:", xdg.ConfigHome)
log.Println("Config directories:", xdg.ConfigDirs)
log.Println("Home state directory:", xdg.StateHome)
log.Println("Cache directory:", xdg.CacheHome)
log.Println("Runtime directory:", xdg.RuntimeDir)
// Other common directories.
log.Println("Home directory:", xdg.Home)
log.Println("Application directories:", xdg.ApplicationDirs)
log.Println("Font directories:", xdg.FontDirs)
// Obtain a suitable location for application config files.
// ConfigFile takes one parameter which must contain the name of the file,
// but it can also contain a set of parent directories. If the directories
// don't exist, they will be created relative to the base config directory.
configFilePath, err := xdg.ConfigFile("appname/config.yaml")
if err != nil {
log.Fatal(err)
}
log.Println("Save the config file at:", configFilePath)
// For other types of application files use:
// xdg.DataFile()
// xdg.StateFile()
// xdg.CacheFile()
// xdg.RuntimeFile()
// Finding application config files.
// SearchConfigFile takes one parameter which must contain the name of
// the file, but it can also contain a set of parent directories relative
// to the config search paths (xdg.ConfigHome and xdg.ConfigDirs).
configFilePath, err = xdg.SearchConfigFile("appname/config.yaml")
if err != nil {
log.Fatal(err)
}
log.Println("Config file was found at:", configFilePath)
// For other types of application files use:
// xdg.SearchDataFile()
// xdg.SearchStateFile()
// xdg.SearchCacheFile()
// xdg.SearchRuntimeFile()
}
XDG user directories
package main
import (
"log"
"github.com/adrg/xdg"
)
func main() {
// XDG user directories.
log.Println("Desktop directory:", xdg.UserDirs.Desktop)
log.Println("Download directory:", xdg.UserDirs.Download)
log.Println("Documents directory:", xdg.UserDirs.Documents)
log.Println("Music directory:", xdg.UserDirs.Music)
log.Println("Pictures directory:", xdg.UserDirs.Pictures)
log.Println("Videos directory:", xdg.UserDirs.Videos)
log.Println("Templates directory:", xdg.UserDirs.Templates)
log.Println("Public directory:", xdg.UserDirs.PublicShare)
}
Stargazers over time
Contributing
Contributions in the form of pull requests, issues or just general feedback,
are always welcome.
See [CONTRIBUTING.MD](CONTRIBUTING.md).
Contributors: adrg, wichert, bouncepaw, gabriel-vasile, KalleDK, nvkv, djdv.
References
For more information see:
License
Copyright (c) 2014 Adrian-George Bostan.
This project is licensed under the MIT license. See [LICENSE](LICENSE) for more details.
*Note that all licence references and agreements mentioned in the xdg-go README section above
are relevant to that project's source code only.