pathutil

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Overview

Package pathutil handles platform-independent project paths.

Index

Constants

This section is empty.

Variables

View Source
var ErrTraversal = errors.New("pathutil: path escapes root")

ErrTraversal is returned when a relative path would escape its base directory via ".." segments.

Functions

func Base

func Base(p string) string

Base returns the final element of p.

func Clean

func Clean(p string) string

Clean normalizes separators and simplifies a path without filesystem access.

func Dir

func Dir(p string) string

Dir returns the cleaned parent directory of p.

func EqualFold

func EqualFold(a, b string) bool

EqualFold compares normalized paths without case sensitivity.

func Ext

func Ext(p string) string

Ext returns the file extension of p, including the leading ".", or "" if p's base name has none.

func HasTraversal

func HasTraversal(rel string) bool

HasTraversal reports whether rel escapes through a ".." segment.

func IsAbs

func IsAbs(p string) bool

IsAbs reports whether p is absolute under Unix ("/foo"), Windows drive ("C:\foo", "C:/foo"), or UNC (`\\server\share`) conventions.

func Join

func Join(elems ...string) string

Join joins path elements with "/" and cleans the result.

func SafeJoin

func SafeJoin(root, rel string) (string, error)

SafeJoin joins root and rel, rejecting absolute or escaping rel paths.

func ToSlash

func ToSlash(p string) string

ToSlash normalizes path separators to "/", accepting both "/" and "\" in the input regardless of host OS.

func VolumeName

func VolumeName(p string) string

VolumeName returns the Windows drive-letter volume prefix of p (e.g. "C:"), or "" if p has none.

Types

This section is empty.

Jump to

Keyboard shortcuts

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