Documentation
¶
Index ¶
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
Types ¶
type Local ¶
type Local [2]string
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 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) ToSystem ¶ added in v0.1.8
ToSystem transforms the given Local path into the most common string notation for the running system. 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 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