Documentation
¶
Overview ¶
Package impath (immutable path) provides immutable and distinguishable types for absolute and relative paths. This allows for strong guarantees at compile time, improves legibility and reduces maintenance burden.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotAbsolute indicates that the path is not absolute. ErrNotAbsolute = errors.New("path is not absolute") // ErrNotRelative indicates that the path is not relative. ErrNotRelative = errors.New("path is not relative") // ErrNotDescendant indicates that the target is a descendant of base. ErrNotDescendant = errors.New("target is not a descendant of base") // Root is / on unix-like systems and c:\ on Windows. Root = os.Getenv("SYSTEMDRIVE") + string(os.PathSeparator) )
Functions ¶
This section is empty.
Types ¶
type Absolute ¶
type Absolute struct {
// contains filtered or unexported fields
}
Absolute represents an immutable absolute path. The zero value is Root.
func Abs ¶
Abs creates a new absolute and clean path from the specified elements.
If the specified elements do not join to a valid absolute path, ErrNotAbsolute is returned. If the joined path does not contain consecutive separators or dot elements, filepath.Clean is not called.
func MustAbs ¶
MustAbs is a convenient wrapper of Abs that is useful for constant paths.
If the specified elements do not join to a valid absolute path, this function panics.
type Relative ¶
type Relative struct {
// contains filtered or unexported fields
}
Relative represents an immutable relative path. The zero value is the empty path, which is an alias to the current directory `.`.
func Descendant ¶
Descendant returns a relative path to the base such that when joined together with base using filepath.Join(base, path), the result is lexically equivalent to target.
The returned error is nil or ErrNotDescendant.
func MustRel ¶
MustRel is a convenient wrapper of Rel that is useful for constant paths.
If the specified elements do not join to a valid relative path, this function panics.
func Rel ¶
Rel creates a new relative and clean path from the specified elements.
If the specified elements do not join to a valid relative path, ErrNotRelative is returned.