path

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 7 Imported by: 50

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPath = errors.Error("invalid path: %s")
	ErrInvalidName = errors.Error("invalid name: %s")
)

Functions

func Base

func Base(p Path) string

However: Base(p Path) returns the last part, i.e. for directories including the / at the end so joining Dir() and Base() will give the complete relative path

func Drive

func Drive(a Local) string

Drive returns the drive letter, followed by a : for a windows absolute path and an empty string for non windows paths

func IsAbs

func IsAbs(p Path) bool

func IsDir

func IsDir(p Path) bool

returns true, if the path ends in a slash

func IsValid

func IsValid(name string) bool

func Name

func Name(p Path) string

returns the name (the part after the last slash) if p is a directory, the last slash will not be part of the name that means, that joining Dir() and Name() will not be a directory name, but a filename However: Base(p Path) returns the last part, i.e. for directories including the / at the end so joining Dir() and Base() will give the complete relative path

func NetShare

func NetShare(a Local) string

NetShare returns the network share for a windows UNC absolute path and an empty string otherwise

func Validate

func Validate(name string) error

Types

type Absolute

type Absolute interface {
	Path
	Head() string
}

type Local

type Local [2]string

func MustLocal

func MustLocal(abs string) Local

MustLocal calls ParseLocal, panics if the later returns an error and returns the Local path otherwise

func MustWD

func MustWD() Local

WD returns the working directory as an absolute path Local calls ParseLocal, panics if the later returns an error and returns the Absolute path otherwise

func ParseLocal

func ParseLocal(abs string) (a Local, err error)

ParseLocal parses local fs paths (they are always absolute). that basically means Unix and windows system paths and Windows UNC paths. a windows path might be entered the following ways: A: `C:\a\b\c\` (ending in a backslash means directory) B: `C:/a/b/c/` (ending in a slash means directory) C: `\\share\sub\directories\` (ending in a backslash means directory) D: `\\share/sub/directories/` (ending in a slash means directory) in case A and B the resulting Absolute path will be Head: C:/ Tail: a/b/c/ in case C and D the resulting Absolute path will be Head: \\share/ Tail: sub/directories/ if the given abs does not have the correct syntax or is not absolute, ParseLocal will return an error

func ParseWD

func ParseWD() (a Local, err error)

func ToLocal

func ToLocal(abs Absolute) Local

ToLocal creates a Local path out of an absolute path

func (Local) Head

func (a Local) Head() string

func (Local) Join

func (a Local) Join(parts ...string) Local

Join returns a new Absolute that has the same head but a tail that is the join of the old tail and the given parts within the parts, directories must end with a slash /

func (Local) Relative

func (a Local) Relative() Relative

func (Local) Resolve

func (a Local) Resolve(r Relative) Local

Resolve resolves in the context of the path of local

func (Local) String

func (a Local) String() string

func (Local) ToLocString

func (a Local) ToLocString() string

ToLocString transforms the given Local path into the local string notation. That means that the final path-seperator for a directory is dropped. Also the resulting string is absolute / complete and does not contain jumpers like . and .. (it is cleaned) Unix system paths are returned as is, just without a final /, if it is a directory Windows system paths are transformed by replacing the / with a backslash \ e.g. C:\a\b\c (the final backslash would also be dropped, if it is a directory) Windows UNC paths are also transformed by replacing the / with a backslash \ e.g. \\myshare\a\b\c if a is non of the supported paths, an empty string is returned

type Path

type Path interface {
	String() string
	Relative() Relative
}

func Dir

func Dir(p Path) Path

returns the dir (the part before the last slash)

type Relative

type Relative string

Relative is a relative path, i.e. a path that does neither start with a slash, nor with a schema.

func (Relative) Join

func (r Relative) Join(parts ...string) Relative

Join returns a new relative path by joining the old one with the given parts. within the parts, directories must end with a slash /

func (Relative) Relative

func (r Relative) Relative() Relative

Relative fullfills the the Path interface and returns the relative part of the path, which is always itself.

func (Relative) String

func (r Relative) String() string

String return the representation of the path as a string.

type Remote

type Remote struct {
	*url.URL
}

func MustRemote

func MustRemote(u string) *Remote

MustRemote calls ParseRemote, panics if the later returns an error and returns the Remote path otherwise

func ParseRemote

func ParseRemote(u string) (*Remote, error)

ParseRemote parses remote fs paths, i.e. urls (they are always absolute). the given url should not have querys, nor fragments

func ToRemote

func ToRemote(abs Absolute) (*Remote, error)

ToRemote creates a Remote path out of an absolute path

func (*Remote) Head

func (u *Remote) Head() string

func (*Remote) Join

func (u *Remote) Join(parts ...string) *Remote

Join joins based on the relative path

func (*Remote) Relative

func (u *Remote) Relative() Relative

func (*Remote) Resolve

func (u *Remote) Resolve(r Relative) *Remote

Resolve resolves in the context of Head()

Jump to

Keyboard shortcuts

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