Documentation
¶
Index ¶
- Variables
- func Base(p Path) string
- func Clean(s string) string
- func DriveLetter(a Local) string
- func Ext(p Path) 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
- func MustDirFromSystem(p string) (l Local)
- func MustFileFromSystem(p string) (l Local)
- func MustLocal(abs string) Local
- func MustWD() Local
- func ParseDirFromSystem(p string) (l Local, err error)
- func ParseFileFromSystem(p string) (l Local, err error)
- func ParseLocal(path string) (a Local, err error)
- func ParseWD() (a Local, err error)
- func ToLocal(abs Absolute) 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 DriveLetter ¶ added in v0.17.0
DriveLetter returns the drive letter, followed by a : for a windows absolute path and an empty string for non windows paths
func Ext ¶ added in v0.18.2
Ext returns the extension of the given path. If the path has no extension, it returns the empty string If the path is a directory, it returns the slash / Otherwise it returns the extension, as filepath.Ext (i.e. with prefixed dot)
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 MustDirFromSystem ¶ added in v0.13.0
MustDirFromSystem is like ParseDirFromSystem, just that it panics on error
func MustFileFromSystem ¶ added in v0.13.0
MustFileFromSystem is like ParseFileFromSystem, 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 ParseDirFromSystem ¶ added in v0.13.0
ParseDirFromSystem parses an existing local path that must be a directory the path might be absolute or relative (than it is relative to the current working directory) the given path might end in a slash or not. the resultig Local will end in a slash if p is an empty string, or a . the working directory is chosen
func ParseFileFromSystem ¶ added in v0.13.0
ParseFileFromSystem parses an existing local path that must be a file the path might be absolute or relative (than it is relative to the current working directory) the given path must not end in a slash. if p must not be an empty string, or .
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 /
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) Depth ¶ added in v0.16.0
Depth returns the depth of the file / dir relative to its starting position, i.e. the number of parent directories. Depth return -1 for the root directory
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