pathutil

package
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Depth

func Depth(path string) int

Depth returns the number of path components. For absolute paths, this counts only the actual components (not the leading separator).

func EnsureTrailingSep

func EnsureTrailingSep(path string) string

EnsureTrailingSep adds a trailing separator if not present.

func FromURL added in v0.0.32

func FromURL(urlPath string) string

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

func HasLeadingSep(path string) bool

HasLeadingSep checks if a path starts with a separator (either / or \ or \\).

func HasTrailingSep

func HasTrailingSep(path string) bool

HasTrailingSep checks if path ends with a separator.

func IsAbs

func IsAbs(path string) bool

IsAbs reports whether a path is absolute. Handles Unix paths (/path), Windows paths (C:\path), and UNC paths (\\server\share).

func Join

func Join(parts []string, addLeadingSep bool) string

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

func Parent(path string) string

Parent returns the parent directory of a path. Returns empty string if path has no parent.

func Prefix

func Prefix(path string) string

Prefix returns the prefix of an absolute path. For Unix: "/" For Windows: "C:\" For UNC: "\\server\share" For relative paths: ""

func Split

func Split(path string) ([]string, bool)

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

func StripTrailingSep(path string) string

StripTrailingSep removes trailing separator from path.

func ToURL added in v0.0.32

func ToURL(path string) string

ToURL converts a filesystem path to a URL-safe path. On Windows: converts backslashes to forward slashes (C:\Users -> C:/Users) On Linux: path is already URL-safe (forward slashes) This is used when sending paths to clients via URLs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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