github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/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      released: v2.7.0
    13      description: |
    14        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 `/`.
    15  
    16        A wrapper for Go's [`path.Base`](https://golang.org/pkg/path/#Base) function.
    17      pipeline: true
    18      arguments:
    19        - name: path
    20          required: true
    21          description: The input path
    22      examples:
    23        - |
    24          $ gomplate -i '{{ path.Base "/tmp/foo" }}'
    25          foo
    26    - name: path.Clean
    27      released: v2.7.0
    28      description: |
    29        Clean returns the shortest path name equivalent to path by purely lexical processing.
    30  
    31        A wrapper for Go's [`path.Clean`](https://golang.org/pkg/path/#Clean) function.
    32      pipeline: true
    33      arguments:
    34        - name: path
    35          required: true
    36          description: The input path
    37      examples:
    38        - |
    39          $ gomplate -i '{{ path.Clean "/tmp//foo/../" }}'
    40          /tmp
    41    - name: path.Dir
    42      released: v2.7.0
    43      description: |
    44        Returns all but the last element of path, typically the path's directory.
    45  
    46        A wrapper for Go's [`path.Dir`](https://golang.org/pkg/path/#Dir) function.
    47      pipeline: true
    48      arguments:
    49        - name: path
    50          required: true
    51          description: The input path
    52      examples:
    53        - |
    54          $ gomplate -i '{{ path.Dir "/tmp/foo" }}'
    55          /tmp
    56    - name: path.Ext
    57      released: v2.7.0
    58      description: |
    59        Returns the file name extension used by path.
    60  
    61        A wrapper for Go's [`path.Ext`](https://golang.org/pkg/path/#Ext) function.
    62      pipeline: true
    63      arguments:
    64        - name: path
    65          required: true
    66          description: The input path
    67      examples:
    68        - |
    69          $ gomplate -i '{{ path.Ext "/tmp/foo.csv" }}'
    70          .csv
    71    - name: path.IsAbs
    72      released: v2.7.0
    73      description: |
    74        Reports whether the path is absolute.
    75  
    76        A wrapper for Go's [`path.IsAbs`](https://golang.org/pkg/path/#IsAbs) function.
    77      pipeline: true
    78      arguments:
    79        - name: path
    80          required: true
    81          description: The input path
    82      examples:
    83        - |
    84          $ gomplate -i 'the path is {{ if (path.IsAbs "/tmp/foo.csv") }}absolute{{else}}relative{{end}}'
    85          the path is absolute
    86          $ gomplate -i 'the path is {{ if (path.IsAbs "../foo.csv") }}absolute{{else}}relative{{end}}'
    87          the path is relative
    88    - name: path.Join
    89      released: v2.7.0
    90      description: |
    91        Joins any number of path elements into a single path, adding a separating slash if necessary.
    92  
    93        A wrapper for Go's [`path.Join`](https://golang.org/pkg/path/#Join) function.
    94      arguments:
    95        - name: elem...
    96          required: true
    97          description: The path elements to join (0 or more)
    98      examples:
    99        - |
   100          $ gomplate -i '{{ path.Join "/tmp" "foo" "bar" }}'
   101          /tmp/foo/bar
   102    - name: path.Match
   103      released: v2.7.0
   104      description: |
   105        Reports whether name matches the shell file name pattern.
   106  
   107        A wrapper for Go's [`path.Match`](https://golang.org/pkg/path/#Match) function.
   108      arguments:
   109        - name: pattern
   110          required: true
   111          description: The pattern to match on
   112        - name: path
   113          required: true
   114          description: The path to match
   115      examples:
   116        - |
   117          $ gomplate -i '{{ path.Match "*.csv" "foo.csv" }}'
   118          true
   119    - name: path.Split
   120      released: v2.7.0
   121      description: |
   122        Splits path immediately following the final slash, separating it into a directory and file name component.
   123  
   124        The function returns an array with two values, the first being the directory, and the second the file.
   125  
   126        A wrapper for Go's [`path.Split`](https://golang.org/pkg/path/#Split) function.
   127      pipeline: true
   128      arguments:
   129        - name: path
   130          required: true
   131          description: The input path
   132      examples:
   133        - |
   134          $ gomplate -i '{{ $p := path.Split "/tmp/foo" }}{{ $dir := index $p 0 }}{{ $file := index $p 1 }}dir is {{$dir}}, file is {{$file}}'
   135          dir is /tmp/, file is foo