pathutil

package
v0.0.0-...-129dccd Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HomeDir

func HomeDir() (string, error)

HomeDir returns the current user's home directory.

func HomeDirOf

func HomeDirOf(u string) (string, error)

HomeDirOf returns a user's home directory.

func Resolve

func Resolve(p string) (string, error)

Resolve resolves p to an absolute path.

func ResolveFrom

func ResolveFrom(base, p string) (string, error)

ResolveFrom resolves p to an absolute path, relative to base.

func SortByDistance

func SortByDistance(base string, paths []string, baseDist Distance)

SortByDistance sorts paths according to their "distance" from base, according to Distance(base, path). Any two paths with the same distance from base are further sorted by their name.

Types

type Distance

type Distance uint32

Distance is a numerical distance between two paths

const (
	// PreferBase is the zero distance. When passed to SortByDistance(), the
	// base path is sorted to the top.
	PreferBase Distance = 0

	// PreferChildren is a distance midway between children of base paths, and
	// non-children. When passed to SortByDistance(), the base path is sorted
	// below its own children, but above non-children.
	PreferChildren Distance = math.MaxUint32 / 2

	// PreferOther is the maximimum distance. When passed to SortByDistance(),
	// the base path is sorted to the bottom.
	PreferOther Distance = math.MaxUint32
)

func DistanceBetween

func DistanceBetween(base, target string, baseDist Distance) (dist Distance)

DistanceBetween returns the "distance" from base to target. The more "hops"\ required to move from base to target, the larger the distance. Targets that are children of base are "closer" than targets that are not. If target is equal to base, the distance is baseDist.

Jump to

Keyboard shortcuts

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