Package xdg

import "github.com/BurntSushi/xdg"
Overview
Index

Overview ▾

type Paths

type Paths struct {
    // When non-empty, this will be the first directory searched.
    Override string

    // The suffix path appended to XDG directories.
    // i.e., "wingo" and NOT "/home/andrew/.config/wingo"
    XDGSuffix string

    // The path in which your data files live inside your project directory.
    // This should include your Go import path plus the directory containing
    // files in your repo. This is used as a last resort to find files.
    // (And it will only work if your package was installed using the GOPATH
    // environment.)
    //
    // N.B. XDGSuffix is not used here,
    // i.e., "github.com/BurntSushi/wingo/config"
    GoImportPath string
}

Paths determines which directories to search. The first directory containing a matching file is used. Here is the order:

Override is always checked first.

Directories specified in the XDG spec are searched after "XDGSuffix" is appended.

For configuration files, these are:

$XDG_CONFIG_HOME (or $HOME/.config when not set)
Directories in $XDG_CONFIG_DIRS (or /etc/xdg when not set)

For data files, these are:

$XDG_DATA_HOME (or $HOME/.local/share when not set)
Directories in $XDG_DATA_DIRS (or /usr/local/share:/usr/share when not set)

For runtime files, these are:

$XDG_RUNTIME_DIR (or /tmp when not set; implementation defined)

Finally, the directory specified by GoImportPath is searched in all source directories reported by the `go/build` package.

func (Paths) ConfigFile

func (ps Paths) ConfigFile(name string) (string, error)

ConfigFile returns a file path containing the configuration file specified. If one cannot be found, an error will be returned which contains a list of all file paths searched.

func (Paths) DataFile

func (ps Paths) DataFile(name string) (string, error)

DataFile returns a file path containing the data file specified. If one cannot be found, an error will be returned which contains a list of all file paths searched.

func (Paths) MustError

func (ps Paths) MustError(fpath string, err error) []byte

MustError is like MustPanic, but instead of panicing when something goes wrong, it prints the error to stderr and calls os.Exit(1).

func (Paths) MustPanic

func (ps Paths) MustPanic(fpath string, err error) []byte

MustPanic takes the return values of ConfigFile or DataFile, reads the file into a []byte, and returns the bytes.

If the operation does not succeed, it panics.

func (Paths) RuntimeFile

func (ps Paths) RuntimeFile(name string) (string, error)

RuntimeFile returns a file path containing the runtime file specified. If one cannot be found, an error will be returned which contains a list of all file paths searched.