Documentation
¶
Index ¶
- Variables
- func Base(p Path) string
- func Clean(s string) string
- func Drive(a Local) string
- func IsAbs(p Path) bool
- func IsDir(p Path) bool
- func IsValid(name string) bool
- func Name(p Path) string
- func NetShare(a Local) string
- func ToSystem(p Path) string
- func Validate(name string) error
- type Absolute
- type Local
- type Path
- type Relative
- type Remote
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidPath = errors.Error("invalid path: %s") ErrInvalidName = errors.Error("invalid name: %s") )
Functions ¶
func Base ¶
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 ¶
Drive returns the drive letter, followed by a : for a windows absolute path and an empty string for non windows paths
func Name ¶
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 ¶
NetShare returns the network share for a windows UNC absolute path and an empty string otherwise
func ToSystem ¶ added in v0.11.0
ToSystem transforms the given Path into the most common string notation for the running system. (e.g. directories without ending slashes, backslashes instead of slashes as separators etc) For Local paths it returns the absolute path. For Relative path, it returns the relative path. For everything else, it it calling the Relative method to transform it into a relative path and uses this relative paths transformation. The resulting path is a canoncial cleaned path of the running system, without "jumps" (like ./ and ../).
Types ¶
type Local ¶
type Local [2]string
func MustFromSystem ¶ added in v0.9.0
MustFromSystem is like ParseFromSystem, just that it panics on error
func MustLocal ¶
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 ParseFromSystem ¶ added in v0.7.0
ParseFromSystem parses an existing local path that might be a file or a directory the path might be absolute or relative (than it is relative to the current working directory) directory paths might end in a slash or not, files however must not end in a slash if p is an empty string, the working directory is chosen if the path does not exists, an error is returned
func ParseLocal ¶
ParseLocal parses a local fs path. The returned path is a Local, which in turn is an absolute path. If the given path does not have the correct syntax, ParseLocal will return an error. Syntax A path that is a directory must always end in a separator, which is the slash / on unix and might be a slash / or backslash \ on windows systems. path might be one of the following:
- "", `.`, `./` or `.\`: then the current local working directory is parsed and returned
- starting with `./` or `.\`: then the rest of the path would be considered to be relative to the local working directory
- a local windows path that is starting with a drive letter, followed by a colon and optionally a rest path starting with a separator that can be either the slash / or the backslash \, e.g. `c:`, `G:`, `c:/`, `G:/`, `c:\`, `G:\`, `c:/a.txt`, `G:/b.txt`, `C:\a\b\c\`, `g:/a/b/c/`
- a windows network share in UNC notation (must start with two baslslashes \\) optionally followed by a rest path with the above separator, e.g. `\\host\share\`, `\\host/share/`, `\\host\share\sub\dir\`, `\\host/share/sub/dir/`, `\\host\share\file.txt`
- an absolute unix path (must start with a slash), e.g. `/`, `/a.txt`, `/a/`, `/a/b/c.txt`
Resulting heads and tails: Since a Local is just a fixed array of two strings, where the first one is the absolute head and the second on is the relative tail to that here are some examples, how the resulting heads and tails would be.
- "", `.`, `./` or `.\`: head is the absolute path of the working directory, tail is empty
- starting with `./` or `.\` : head is the absolute path of the working directory, tail is the relative path that is following where backslashes are replaced by slashes, e.g. `.\a\b\c.txt` results in the tail `a/b/c.txt`
- a local windows path that is starting with a drive letter: head is the drive letter and tail the rest, e.g. `C:\a\b\c\` would result in a head of `c:/` and a tail of `a/b/c/`
- a windows network share in UNC notation would end up with a head of the host and share and the tail would be the rest, e.g. `\\host\share\sub\dir\a.txt`: would result in the head `\\host\share/` and the tail `sub/dir/a.txt`
- an absolute unix path would result in the head being the root dir and the tail being the rest, e.g. `/a/b/c.txt` would result in a head of `/` and a tail of `a/b/c.txt`
The plattform specific string notation of a Local (for the compiled plattform) can always be returned via Local.ToSystem()
func (Local) Join ¶
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) RootRelative ¶ added in v0.9.0
RootRelative returns a normal relative path on unix and on windows a relative path to an imaginary root that would reside above the drive letters, so that the returned relative path would start with the lowercase drive letter, followed by a slash and the normal rest of the path e.g.
C:\Windows\Temp => c/Windows/Temp D:\files => d/files /hi/ho => hi/ho
It is supposed to be used with the rootfs in order to have a crossplattform root fs.
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 ¶
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 ¶
Relative fullfills the the Path interface and returns the relative part of the path, which is always itself.
type Remote ¶
func MustRemote ¶
MustRemote calls ParseRemote, panics if the later returns an error and returns the Remote path otherwise
func ParseRemote ¶
ParseRemote parses remote fs paths, i.e. urls (they are always absolute). the given url should not have querys, nor fragments