path functions
gomplate’s path functions are split into 2 namespaces:
path, which is useful for manipulating slash-based (/) paths, such as in URLsfilepath, which should be used for local filesystem paths, especially when Windows paths may be involved.
This page documents the path namespace - see also the filepath documentation.
These functions are wrappers for Go’s path and path/filepath packages.
path.Base
Returns the last element of path. Trailing slashes are removed before extracting the last element. If the path is empty, Base returns .. If the path consists entirely of slashes, Base returns /.
A wrapper for Go’s path.Base function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
path.Clean
Clean returns the shortest path name equivalent to path by purely lexical processing.
A wrapper for Go’s path.Clean function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
path.Dir
Returns all but the last element of path, typically the path’s directory.
A wrapper for Go’s path.Dir function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
path.Ext
Returns the file name extension used by path.
A wrapper for Go’s path.Ext function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
path.IsAbs
Reports whether the path is absolute.
A wrapper for Go’s path.IsAbs function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
path.Join
Joins any number of path elements into a single path, adding a separating slash if necessary.
A wrapper for Go’s path.Join function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
elem... |
(required) The path elements to join (0 or more) |
Examples
path.Match
Reports whether name matches the shell file name pattern.
A wrapper for Go’s path.Match function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
pattern |
(required) The pattern to match on |
path |
(required) The path to match |
Examples
path.Split
Splits path immediately following the final slash, separating it into a directory and file name component.
The function returns an array with two values, the first being the directory, and the second the file.
A wrapper for Go’s path.Split function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |