Skip to content

Package xdgbasedir implements a freedesktop XDG Base Directory Specification for Go

License

Notifications You must be signed in to change notification settings

zchee/go-xdgbasedir

Repository files navigation

go-xdgbasedir

linux / darwin windows godoc.org
circleci.com appveyor-badge godoc.org
coverage Release XDG Version
codecov.io Release XDG version

Package xdgbasedir implements a freedesktop XDG Base Directory Specification for Go.

freedesktop.org XDG Base Directory Specification reference:

Current specification version:

  • 0.8

Specification

func linux, darwin (Mode: Unix) darwin (Mode: Native)
DataHome() ~/.local/share ~/Library/Application Support
ConfigHome() ~/.config ~/Library/Preferences
DataDirs() /usr/local/share:/usr/share ~/Library/Application Support
ConfigDirs() /etc/xdg ~/Library/Preferences
CacheHome() ~/.cache ~/Library/Caches
RuntimeDir() /run/user/$(id -u) ~/Library/Application Support
func windows
DataHome() C:\Users\%USER%\AppData\Roaming
ConfigHome() C:\Users\%USER%\AppData\Roaming
DataDirs() C:\Users\%USER%\AppData\Roaming
ConfigDirs() C:\Users\%USER%\AppData\Roaming
CacheHome() C:\Users\%USER%\AppData\Local\cache
RuntimeDir() C:\Users\%USER%

Note

XDG Base Directory Specification is mainly for GNU/Linux. It does not mention which directory to use with macOS(darwin) or windows.
So, We referred to the qt standard paths document for the corresponding directory.

We prepared a Mode for users using macOS like Unix. It's darwin GOOS specific.
If it is set to Unix, it refers to the same path as linux. If it is set to Native, it refers to the Specification path.
By default, Unix.

Unix:

// +build darwin

package main

import (
	"fmt"

	"github.com/zchee/go-xdgbasedir"
)

func init() {
	xdgbasedir.Mode = xdgbasedir.Unix // optional, default is Unix
}

func main() {
	fmt.Println(xdgbasedir.DataHome())

	// Output:
	// "/Users/foo/.local/share"
}

Native:

// +build darwin

package main

import (
	"fmt"

	"github.com/zchee/go-xdgbasedir"
)

func init() {
	xdgbasedir.Mode = xdgbasedir.Native
}

func main() {
	fmt.Println(xdgbasedir.DataHome())

	// Output:
	// "/Users/foo/Library/Application Support"
}

Badge

powered by shields.io.

XDGBaseDirSpecVersion

markdown:

[![XDGBaseDirSpecVersion](https://img.shields.io/badge/%20XDG%20Base%20Dir%20-%200.8-blue.svg?style=for-the-badge)](https://specifications.freedesktop.org/basedir-spec/0.8/)