linux / darwin | windows | godoc.org |
---|---|---|
coverage | Release | XDG Version |
Package xdgbasedir
implements a freedesktop XDG Base Directory Specification for Go.
- https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html
- https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
- 0.8
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% |
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"
}
powered by shields.io.
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/)