Help us shape the future of Go! Take the 2026 Go Developer Survey

paths

package
v1.61.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package paths centralizes home-directory resolution and path expansion.

All home-dir lookups should go through this package instead of calling os.UserHomeDir directly, so tests can stub UserHomeDir and behavior stays consistent (tilde + env expansion) across commands.

Index

Constants

This section is empty.

Variables

View Source
var UserHomeDir = os.UserHomeDir

UserHomeDir is mockable for testing. Defaults to os.UserHomeDir.

Functions

func Expand

func Expand(path string) string

Expand expands a leading "~" and environment variables in path. "~" alone maps to home; "~/x" maps to $HOME/x. Other values pass through os.ExpandEnv unchanged. On home lookup failure the input is returned with env expansion only.

func Home

func Home() (string, error)

Home returns the current user's home directory.

func JoinHome

func JoinHome(elem ...string) (string, error)

JoinHome joins elem onto the home directory.

func MustHome

func MustHome() string

MustHome returns the home directory or an empty string on error. Use when a best-effort fallback path is acceptable (e.g. display defaults).

Types

This section is empty.

Jump to

Keyboard shortcuts

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