paths

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package paths provides cross-platform directory resolution for application configuration, data, and cache storage.

This package abstracts platform differences in standard directory locations:

  • Unix/Linux: XDG Base Directory Specification (~/.config, ~/.local/share, etc.)
  • macOS: ~/Library/Application Support, ~/Library/Caches
  • Windows: %APPDATA%, %LOCALAPPDATA%, %ProgramData%

All functions return absolute paths. App-specific functions (AppConfig, AppData, etc.) will create the directory if it doesn't exist.

Index

Constants

This section is empty.

Variables

View Source
var ErrHomeNotFound = errors.New("oscompat/paths: home directory not found")

ErrHomeNotFound is returned when the user's home directory cannot be determined.

View Source
var ErrInvalidAppName = errors.New("oscompat/paths: app name cannot be empty")

ErrInvalidAppName is returned when an empty app name is provided.

Functions

func AppCache

func AppCache(appName string) (string, error)

AppCache returns the app-specific cache directory, creating it if needed. The directory follows platform conventions:

  • Unix/Linux: ~/.cache/<appName>
  • macOS: ~/Library/Caches/<appName>
  • Windows: %LOCALAPPDATA%\<appName>\cache

func AppConfig

func AppConfig(appName string) (string, error)

AppConfig returns the app-specific configuration directory, creating it if needed. The directory follows platform conventions:

  • Unix/Linux: ~/.config/<appName>
  • macOS: ~/Library/Application Support/<appName>
  • Windows: %APPDATA%\<appName>

func AppData

func AppData(appName string) (string, error)

AppData returns the app-specific data directory, creating it if needed. The directory follows platform conventions:

  • Unix/Linux: ~/.local/share/<appName>
  • macOS: ~/Library/Application Support/<appName>
  • Windows: %LOCALAPPDATA%\<appName>

func AppRuntime

func AppRuntime(appName string) (string, error)

AppRuntime returns the app-specific runtime directory, creating it if needed. This is for runtime files like sockets and PIDs that should not persist across reboots.

  • Unix/Linux: $XDG_RUNTIME_DIR/<appName> or /tmp/<appName>-<uid>
  • macOS: ~/Library/Application Support/<appName>/run
  • Windows: %LOCALAPPDATA%\<appName>\run

func Home

func Home() (string, error)

Home returns the current user's home directory.

func SystemAppConfig

func SystemAppConfig(appName string) (string, error)

SystemAppConfig returns the system-wide app configuration directory. This requires elevated privileges to write to.

  • Unix/Linux: /etc/<appName>
  • Windows: %ProgramData%\<appName>

func SystemConfig

func SystemConfig() (string, error)

SystemConfig returns the system-wide configuration directory. Returns /etc on Unix systems.

func UserCache

func UserCache() (string, error)

UserCache returns the user-specific cache directory. Follows XDG Base Directory Specification: $XDG_CACHE_HOME or ~/.cache

func UserConfig

func UserConfig() (string, error)

UserConfig returns the user-specific configuration directory. Follows XDG Base Directory Specification: $XDG_CONFIG_HOME or ~/.config

func UserData

func UserData() (string, error)

UserData returns the user-specific data directory. Follows XDG Base Directory Specification: $XDG_DATA_HOME or ~/.local/share

func UserRuntime

func UserRuntime() (string, error)

UserRuntime returns the user-specific runtime directory. Follows XDG Base Directory Specification: $XDG_RUNTIME_DIR or /tmp/<user>-runtime

Types

This section is empty.

Jump to

Keyboard shortcuts

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