Documentation
¶
Overview ¶
Package path provides methods for working with paths (fully compatible with base path package)
Index ¶
- Variables
- func Base(path string) string
- func Clean(path string) string
- func Compact(path string) string
- func Dir(path string) string
- func DirN(path string, n int) string
- func Ext(path string) string
- func IsAbs(path string) bool
- func IsDotfile(path string) bool
- func IsGlob(pattern string) bool
- func IsSafe(path string) bool
- func Join(elem ...string) string
- func JoinSecure(root string, elem ...string) (string, error)
- func Match(pattern, name string) (matched bool, err error)
- func Split(path string) (dir, file string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadPattern = errors.New("Syntax error in pattern")
ErrBadPattern indicates a globbing pattern was malformed
Functions ¶
func Clean ¶
Clean returns the shortest path name equivalent to path by purely lexical processing
Example ¶
Output: /project/abc
func Compact ¶
Compact converts path to compact representation (e.g /some/random/directory/file.txt → /s/r/d/file.txt)
Example ¶
Output: /h/u/j/file.zip
func Dir ¶
Dir returns all but the last element of path, typically the path's directory
Example ¶
Output: /home/user
func DirN ¶
DirN returns first N elements of path
Example ¶
Output: Config dir (→): /home/user/project/config Config dir (←): /home/user/project/config Bin dir (→): /usr/sbin Bin dir (←): /usr/sbin
func IsDotfile ¶
IsDotfile returns true if file name begins with a full stop
Example ¶
Output: /home/user/project/file is dotfile → false /home/user/project/.file is dotfile → true
func IsGlob ¶
IsGlob returns true if given pattern is Unix-like glob
Example ¶
Output: file is glob → false *.file is glob → true
func IsSafe ¶
IsSafe returns true is given path is safe to use (not points to system dirs)
Example ¶
Output: /home/user/project is safe → true /usr/sbin/myapp is safe → false
func Join ¶
Join joins any number of path elements into a single path, adding a separating slash if necessary
Example ¶
Output: /home/user/project/app1/main.go
func JoinSecure ¶
JoinSecure joins all elements of path, makes lexical processing, and evaluating all symlinks. Method returns error if final destination is not a child path of root.
Example ¶
Output: /home/user/project/app2/main.go
Types ¶
This section is empty.