pathutil

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(name string, paths []string) (string, error)

Create returns a suitable location relative to which the file with the specified `name` can be written. The first path from the provided `paths` slice which is successfully created (or already exists) is used as a base path for the file. The `name` parameter should contain the name of the file which is going to be written in the location returned by this function, but it can also contain a set of parent directories, which will be created relative to the selected parent path.

func EnvPath added in v0.5.0

func EnvPath(name string, fallbackPaths ...string) string

EnvPath returns the value of the environment variable with the specified `name` if it is an absolute path, or the first absolute fallback path. All paths are expanded using the `ExpandHome` function.

func EnvPathList added in v0.5.0

func EnvPathList(name string, fallbackPaths ...string) []string

EnvPathList reads the value of the environment variable with the specified `name` and attempts to extract a list of absolute paths from it. If there are none, a list of absolute fallback paths is returned instead. Duplicate paths are removed from the returned slice. All paths are expanded using the `ExpandHome` function.

func Exists

func Exists(path string) bool

Exists returns true if the specified path exists.

func ExpandHome

func ExpandHome(path string) string

ExpandHome substitutes `~` and `$HOME` at the start of the specified `path`.

func First added in v0.5.0

func First(paths []string) string

First returns the first absolute path from the provided slice. The paths in the input slice are expanded using the `ExpandHome` function.

func Search(name string, paths []string) (string, error)

Search searches for the file with the specified `name` in the provided slice of `paths`. The `name` parameter must contain the name of the file, but it can also contain a set of parent directories.

func Unique

func Unique(paths []string) []string

Unique eliminates the duplicate paths from the provided slice and returns the result. The paths are expanded using the `ExpandHome` function and only absolute paths are kept. The items in the output slice are in the order in which they occur in the input slice.

func UserHomeDir added in v0.5.0

func UserHomeDir() string

UserHomeDir returns the home directory of the current user.

Types

This section is empty.

Jump to

Keyboard shortcuts

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