Skip to content

cardigann/xdg-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xdg-go GoDoc codebeat badge

Quickstart

If you just want OS-sensible paths.

configDirs := xdg.ConfigDirs()
dataPath := xdg.DataHome()
cachePath := xdg.CacheHome()

Alternatively you can create a context that would determine full paths for your application files.

app := xdg.App{Name: "someApp"}
configFile := app.ConfigPath("someApp.toml")
dataFile := app.DataPath("data.json")

Supported path types

This is a KISS implementation of the XDG Base Directory Specification. As of now it handles the following path types:

  • Data (XDG_DATA_*) for application-wide or user-wide data.
  • Config (XDG_CONFIG_*) for application-wide or user-wide config.
  • Cache (XDG_CACHE_*)for application-wide or user-wide cached data.

Multi-OS

The specification is Linux centric but this implementation targets more: Linux, OSX and Windows. Default values has been chosen regarding both the specification and the OS conventions. Note than you can override these values with the corresponding environment variables. The following matrix shows the paths you can expect.

Linux/BSDWindowsmacOS
User Config $XDG_CONFIG_HOME ($HOME/.config) %APPDATA% (%USERPROFILE%\AppData\Roaming) $HOME/Library/Preferences
System Config $XDG_CONFIG_DIRS (/etc/xdg) %APPDATA% (%USERPROFILE%\AppData\Roaming) /Library/Preferences:/Library/Application Support
User Data $XDG_DATA_HOME ($HOME/.local/share) %LOCALAPPDATA% (%USERPROFILE%\AppData\Roaming) $HOME/Library
System Data $XDG_DATA_DIRS (/usr/local/share/:/usr/share/) %APPDATA%, %LOCALAPPDATA% (%USERPROFILE%\AppData\Roaming, %USERPROFILE%\AppData\Local) /Library
User Cache $XDG_CACHE_HOME ($HOME/.local/share) %TEMP% (%USERPROFILE%\AppData\Local\Temp) $HOME/Library/Caches

There are a lot of OSes missing but supporting them implies a good knowledge of these conventions and philosophies, contributors maybe?

About

A simple multi-OS implementation of the XDG Base Directory Specification.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%