Documentation
¶
Overview ¶
Package pathutil provides cross-platform path handling utilities. It centralizes path operations to handle both Unix and Windows paths, including UNC paths, consistently throughout the application.
Index ¶
- func Depth(path string) int
- func EnsureTrailingSep(path string) string
- func FromURL(urlPath string) string
- func HasLeadingSep(path string) bool
- func HasTrailingSep(path string) bool
- func IsAbs(path string) bool
- func Join(parts []string, addLeadingSep bool) string
- func Parent(path string) string
- func Prefix(path string) string
- func Split(path string) ([]string, bool)
- func StripTrailingSep(path string) string
- func ToURL(path string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Depth ¶
Depth returns the number of path components. For absolute paths, this counts only the actual components (not the leading separator).
func EnsureTrailingSep ¶
EnsureTrailingSep adds a trailing separator if not present.
func FromURL ¶ added in v0.0.32
FromURL converts a URL path to a filesystem path. It performs the following normalizations: 1. Converts forward slashes to OS separator (backslash on Windows) 2. Resolves . and .. components 3. Removes duplicate separators This is used when receiving paths from clients via URL parameters.
func HasLeadingSep ¶
HasLeadingSep checks if a path starts with a separator (either / or \ or \\).
func HasTrailingSep ¶
HasTrailingSep checks if path ends with a separator.
func IsAbs ¶
IsAbs reports whether a path is absolute. Handles Unix paths (/path), Windows paths (C:\path), and UNC paths (\\server\share).
func Join ¶
Join joins path components using the OS-specific separator. If addLeadingSep is true, adds a leading separator (for absolute paths). Special handling: if first part looks like a drive letter (C:), adds separator after it.
func Parent ¶
Parent returns the parent directory of a path. Returns empty string if path has no parent.
func Prefix ¶
Prefix returns the prefix of an absolute path. For Unix: "/" For Windows: "C:\" For UNC: "\\server\share" For relative paths: ""
func Split ¶
Split splits a path into its components, handling both forward and back slashes. For Windows paths with drive letters (C:\path), the drive letter is preserved as the first component. Returns (parts, isAbs) where parts contains the path components.
func StripTrailingSep ¶
StripTrailingSep removes trailing separator from path.
Types ¶
This section is empty.