xdg

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: LGPL-3.0 Imports: 4 Imported by: 0

README

xdg Go Documentation

Go 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")

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadCache

func ReadCache(subpaths ...string) ([]byte, error)

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

func ReadConfig(subpaths ...string) ([]byte, error)

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

func ReadData(subpaths ...string) ([]byte, error)

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

func ReadState(subpaths ...string) ([]byte, error)

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

func WriteCache(data []byte, subpaths ...string) error

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

func WriteState(data []byte, subpaths ...string) error

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

func WriteSysConfig(data []byte, subpaths ...string) error

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

func WriteSysData(data []byte, subpaths ...string) error

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

func WriteUserConfig(data []byte, subpaths ...string) error

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

func WriteUserData(data []byte, subpaths ...string) error

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.

Jump to

Keyboard shortcuts

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