Documentation ¶
Overview ¶
Package xdg provides helpers for reading and writing files in the XDG Base Directories.
Example usage:
xdg.WriteSysConfig([]byte("some default config"), "myapp", "config.yaml") xdg.WriteUserConfig([]byte("some user config"), "myapp/config.yaml") xdg.WriteState([]byte("some log file"), "myapp", "logs", "errors.log") data, err := xdg.ReadConfig("myapp", "config.yaml") data, err := xdg.ReadCache("myapp", "subdir", "filename")
Index ¶
- func ReadCache(subpaths ...string) ([]byte, error)
- func ReadConfig(subpaths ...string) ([]byte, error)
- func ReadData(subpaths ...string) ([]byte, error)
- func ReadState(subpaths ...string) ([]byte, error)
- func WriteCache(data []byte, subpaths ...string) error
- func WriteState(data []byte, subpaths ...string) error
- func WriteSysConfig(data []byte, subpaths ...string) error
- func WriteSysData(data []byte, subpaths ...string) error
- func WriteUserConfig(data []byte, subpaths ...string) error
- func WriteUserData(data []byte, subpaths ...string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadCache ¶
ReadCache reads path.Join(subpaths...) under $XDG_CACHE_HOME, or $HOME/.cache if $XDG_CACHE_HOME is not defined. It returns an error if $HOME is not defined or if an error occurs when reading the file.
func ReadConfig ¶
ReadConfig reads path.Join(subpaths...) under $XDG_CONFIG_HOME, falling back to the directories defined in $XDG_CONFIG_DIRS, or /etc/xdg if $XDG_CONFIG_DIRS is not defined. It returns an error if an error occurs when reading the file.
func ReadData ¶
ReadData reads path.Join(subpaths...) under $XDG_DATA_HOME, falling back to the directories defined in $XDG_DATA_DIRS, or /usr/local/share:/usr/share if $XDG_DATA_DIRS is not defined. It returns an error if an error occurs when reading the file.
func ReadState ¶
ReadState reads path.Join(subpaths...) under $XDG_STATE_HOME, or $HOME/.local/state if $XDG_STATE_HOME is not defined. It returns an error if $HOME is not defined or if an error occurs when reading the file.
func WriteCache ¶
WriteCache writes data to path.Join(subpaths...) under $XDG_CACHE_HOME, or $HOME/.cache if $XDG_CACHE_HOME is not defined. It creates the directories and file if necessary. It returns an error if $HOME is not defined or if an error occurs when creating the directories or writing the file.
func WriteState ¶
WriteState writes data to path.Join(subpaths...) under $XDG_STATE_HOME, or $HOME/.local/state if $XDG_STATE_HOME is not defined. It creates the directories and file if necessary. It returns an error if $HOME is not defined or if an error occurs when creating the directories or writing the file.
func WriteSysConfig ¶
WriteSysConfig writes data to path.Join(subpaths...) under $sysconfdir/xdg, or /etc/xdg if $sysconfdir is not defined. It creates the directories and file if necessary. It returns an error if an error occurs when creating the directories or writing the file.
func WriteSysData ¶
WriteSysData writes data to path.Join(subpaths...) under $datadir, or /usr/share if $datadir is not defined. It creates the directories and file if necessary. It returns an error if an error occurs when creating the directories or writing the file.
func WriteUserConfig ¶
WriteUserConfig writes data to path.Join(subpaths...) under $XDG_CONFIG_HOME, or $HOME/.config if $XDG_CONFIG_HOME is not defined. It creates the directories and file if necessary. It returns an error if $HOME is not defined or if an error occurs when creating the directories or writing the file.
func WriteUserData ¶
WriteUserData writes data to path.Join(subpaths...) under $XDG_DATA_HOME, or $HOME/.local/share if $XDG_DATA_HOME is not defined. It creates the directories and file if necessary. It returns an error if $HOME is not defined or if an error occurs when creating the directories or writing the file.
Types ¶
This section is empty.