xdg

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2019 License: BSD-3-Clause Imports: 3 Imported by: 33

README

XDG Build status Build Status Go Report Card GoDoc codecov

A cross platform package that tries to follow XDG Standard when possible. Since XDG is linux specific, I am only able to follow standards to the T on linux. But for the other operating systems I am finding similar best practice locations for the files.

Locations Per OS

The following table shows what is used if the envrionment variable is not set. If the variable is set then this package uses that. Linux follows the default standards. Mac does when it comes to the home directory but for system wide it uses the standard /Library/Application Support. As for Windows, the variable defaults are just other environment variables set up by the operation system.

When creating XDG application the Vendor and Application names are appeneded to the end of the path to keep projects unique.

Linux(and BSD) Mac Windows
XDG_DATA_DIRS [/usr/local/share, /usr/share] [/Library/Application Support] %PROGRAMDATA%
XDG_DATA_HOME ~/.local/share ~/Library/Application Support %APPDATA%
XDG_CONFIG_DIRS [/etc/xdg] [/Library/Application Support] %PROGRAMDATA%
XDG_CONFIG_HOME ~/.config ~/Library/Application Support %APPDATA%
XDG_CACHE_HOME ~/.cache ~/Library/Caches %LOCALAPPDATA%

Notes

  • This package does not merge files if they exist across different directories.
  • The Query methods search through the system variables, DIRS, first (when using environment variables first in the variable has presidence). It then checks home variables, HOME.
  • This package will not create any directories for you. In the standard, it states the following:

If, when attempting to write a file, the destination directory is non-existant an attempt should be made to create it with permission 0700. If the destination directory exists already the permissions should not be changed. The application should be prepared to handle the case where the file could not be written, either because the directory was non-existant and could not be created, or for any other reason. In such case it may chose to present an error message to the user.

Documentation

Overview

Package xdg impelements the XDG standard for application file locations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheHome

func CacheHome() string

CacheHome returns the location that should be used for application cache files

func ConfigDirs

func ConfigDirs() []string

ConfigDirs returns a list of locations that should be used for system wide config files

func ConfigHome

func ConfigHome() string

ConfigHome returns the location that should be used for user specific config files

func DataDirs

func DataDirs() []string

DataDirs returns a list of locations that should be used for system wide data files

func DataHome

func DataHome() string

DataHome returns the location that should be used for user specific data files

Types

type XDG

type XDG struct {
	Vendor      string
	Application string
}

XDG is information about the currently running application

func New

func New(vendor, application string) *XDG

New returns an instance of XDG that is used to grab files for application use

func (*XDG) CacheHome

func (x *XDG) CacheHome() string

CacheHome returns the location that should be used for application cache files for this specific application

func (*XDG) ConfigDirs

func (x *XDG) ConfigDirs() []string

ConfigDirs returns a list of locations that should be used for system wide config files for this specific application

func (*XDG) ConfigHome

func (x *XDG) ConfigHome() string

ConfigHome returns the location that should be used for user specific config files for this specific application

func (*XDG) DataDirs

func (x *XDG) DataDirs() []string

DataDirs returns a list of locations that should be used for system wide data files for this specific application

func (*XDG) DataHome

func (x *XDG) DataHome() string

DataHome returns the location that should be used for user specific data files for this specific application

func (*XDG) QueryCache

func (x *XDG) QueryCache(filename string) string

QueryCache looks for the given filename in XDG paths for cache files. Returns an empty string if one was not found.

func (*XDG) QueryConfig

func (x *XDG) QueryConfig(filename string) string

QueryConfig looks for the given filename in XDG paths for config files. Returns an empty string if one was not found.

func (*XDG) QueryData

func (x *XDG) QueryData(filename string) string

QueryData looks for the given filename in XDG paths for data files. Returns an empty string if one was not found.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL