github.com/wuhuizuo/gomplate@v3.5.0+incompatible/docs-src/content/functions/path.yml (about)

     1  ns: path
     2  preamble: |
     3    gomplate's path functions are split into 2 namespaces:
     4    - `path`, which is useful for manipulating slash-based (`/`) paths, such as in URLs
     5    - `filepath`, which should be used for local filesystem paths, especially when Windows paths may be involved.
     6  
     7    This page documents the `path` namespace - see also the [`filepath`](../filepath) documentation.
     8  
     9    These functions are wrappers for Go's [`path`](https://golang.org/pkg/path/) and [`path/filepath`](https://golang.org/pkg/path/filepath/) packages.
    10  funcs:
    11    - name: path.Base
    12      description: |
    13        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 `/`.
    14  
    15        A wrapper for Go's [`path.Base`](https://golang.org/pkg/path/#Base) function.
    16      pipeline: true
    17      arguments:
    18        - name: path
    19          required: true
    20          description: The input path
    21      examples:
    22        - |
    23          $ gomplate -i '{{ path.Base "/tmp/foo" }}'
    24          foo
    25    - name: path.Clean
    26      description: |
    27        Clean returns the shortest path name equivalent to path by purely lexical processing.
    28  
    29        A wrapper for Go's [`path.Clean`](https://golang.org/pkg/path/#Clean) function.
    30      pipeline: true
    31      arguments:
    32        - name: path
    33          required: true
    34          description: The input path
    35      examples:
    36        - |
    37          $ gomplate -i '{{ path.Clean "/tmp//foo/../" }}'
    38          /tmp
    39    - name: path.Dir
    40      description: |
    41        Returns all but the last element of path, typically the path's directory.
    42  
    43        A wrapper for Go's [`path.Dir`](https://golang.org/pkg/path/#Dir) function.
    44      pipeline: true
    45      arguments:
    46        - name: path
    47          required: true
    48          description: The input path
    49      examples:
    50        - |
    51          $ gomplate -i '{{ path.Dir "/tmp/foo" }}'
    52          /tmp
    53    - name: path.Ext
    54      description: |
    55        Returns the file name extension used by path.
    56  
    57        A wrapper for Go's [`path.Ext`](https://golang.org/pkg/path/#Ext) function.
    58      pipeline: true
    59      arguments:
    60        - name: path
    61          required: true
    62          description: The input path
    63      examples:
    64        - |
    65          $ gomplate -i '{{ path.Ext "/tmp/foo.csv" }}'
    66          .csv
    67    - name: path.IsAbs
    68      description: |
    69        Reports whether the path is absolute.
    70  
    71        A wrapper for Go's [`path.IsAbs`](https://golang.org/pkg/path/#IsAbs) function.
    72      pipeline: true
    73      arguments:
    74        - name: path
    75          required: true
    76          description: The input path
    77      examples:
    78        - |
    79          $ gomplate -i 'the path is {{ if (path.IsAbs "/tmp/foo.csv") }}absolute{{else}}relative{{end}}'
    80          the path is absolute
    81          $ gomplate -i 'the path is {{ if (path.IsAbs "../foo.csv") }}absolute{{else}}relative{{end}}'
    82          the path is relative
    83    - name: path.Join
    84      description: |
    85        Joins any number of path elements into a single path, adding a separating slash if necessary.
    86  
    87        A wrapper for Go's [`path.Join`](https://golang.org/pkg/path/#Join) function.
    88      arguments:
    89        - name: elem...
    90          required: true
    91          description: The path elements to join (0 or more)
    92      examples:
    93        - |
    94          $ gomplate -i '{{ path.Join "/tmp" "foo" "bar" }}'
    95          /tmp/foo/bar
    96    - name: path.Match
    97      description: |
    98        Reports whether name matches the shell file name pattern.
    99  
   100        A wrapper for Go's [`path.Match`](https://golang.org/pkg/path/#Match) function.
   101      arguments:
   102        - name: pattern
   103          required: true
   104          description: The pattern to match on
   105        - name: path
   106          required: true
   107          description: The path to match
   108      examples:
   109        - |
   110          $ gomplate -i '{{ path.Match "*.csv" "foo.csv" }}'
   111          true
   112    - name: path.Split
   113      description: |
   114        Splits path immediately following the final slash, separating it into a directory and file name component.
   115  
   116        The function returns an array with two values, the first being the directory, and the second the file.
   117  
   118        A wrapper for Go's [`path.Split`](https://golang.org/pkg/path/#Split) function.
   119      pipeline: true
   120      arguments:
   121        - name: path
   122          required: true
   123          description: The input path
   124      examples:
   125        - |
   126          $ gomplate -i '{{ $p := path.Split "/tmp/foo" }}{{ $dir := index $p 0 }}{{ $file := index $p 1 }}dir is {{$dir}}, file is {{$file}}'
   127          dir is /tmp/, file is foo