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

     1  ns: filepath
     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 `filepath` namespace - see also the [`path`](../path) documentation.
     8  
     9    These functions are wrappers for Go's [`path/filepath`](https://golang.org/pkg/path/filepath/) package.
    10  funcs:
    11    - name: filepath.Base
    12      description: |
    13        Returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns `.`. If the path consists entirely of separators, Base returns a single separator.
    14  
    15        A wrapper for Go's [`filepath.Base`](https://golang.org/pkg/path/filepath/#Base) function.
    16      pipeline: true
    17      arguments:
    18        - name: path
    19          required: true
    20          description: The input path
    21      examples:
    22        - |
    23          $ gomplate -i '{{ filepath.Base "/tmp/foo" }}'
    24          foo
    25    - name: filepath.Clean
    26      description: |
    27        Clean returns the shortest path name equivalent to path by purely lexical processing.
    28  
    29        A wrapper for Go's [`filepath.Clean`](https://golang.org/pkg/path/filepath/#Clean) function.
    30      pipeline: true
    31      arguments:
    32        - name: path
    33          required: true
    34          description: The input path
    35      examples:
    36        - |
    37          $ gomplate -i '{{ filepath.Clean "/tmp//foo/../" }}'
    38          /tmp
    39    - name: filepath.Dir
    40      description: |
    41        Returns all but the last element of path, typically the path's directory.
    42  
    43        A wrapper for Go's [`filepath.Dir`](https://golang.org/pkg/path/filepath/#Dir) function.
    44      pipeline: true
    45      arguments:
    46        - name: path
    47          required: true
    48          description: The input path
    49      examples:
    50        - |
    51          $ gomplate -i '{{ filepath.Dir "/tmp/foo" }}'
    52          /tmp
    53    - name: filepath.Ext
    54      description: |
    55        Returns the file name extension used by path.
    56  
    57        A wrapper for Go's [`filepath.Ext`](https://golang.org/pkg/path/filepath/#Ext) function.
    58      pipeline: true
    59      arguments:
    60        - name: path
    61          required: true
    62          description: The input path
    63      examples:
    64        - |
    65          $ gomplate -i '{{ filepath.Ext "/tmp/foo.csv" }}'
    66          .csv
    67    - name: filepath.FromSlash
    68      description: |
    69        Returns the result of replacing each slash (`/`) character in the path with the platform's separator character.
    70  
    71        A wrapper for Go's [`filepath.FromSlash`](https://golang.org/pkg/path/filepath/#FromSlash) function.
    72      pipeline: true
    73      arguments:
    74        - name: path
    75          required: true
    76          description: The input path
    77      examples:
    78        - |
    79          $ gomplate -i '{{ filepath.FromSlash "/foo/bar" }}'
    80          /foo/bar
    81          C:\> gomplate.exe -i '{{ filepath.FromSlash "/foo/bar" }}'
    82          C:\foo\bar
    83    - name: filepath.IsAbs
    84      description: |
    85        Reports whether the path is absolute.
    86  
    87        A wrapper for Go's [`filepath.IsAbs`](https://golang.org/pkg/path/filepath/#IsAbs) function.
    88      pipeline: true
    89      arguments:
    90        - name: path
    91          required: true
    92          description: The input path
    93      examples:
    94        - |
    95          $ gomplate -i 'the path is {{ if (filepath.IsAbs "/tmp/foo.csv") }}absolute{{else}}relative{{end}}'
    96          the path is absolute
    97          $ gomplate -i 'the path is {{ if (filepath.IsAbs "../foo.csv") }}absolute{{else}}relative{{end}}'
    98          the path is relative
    99    - name: filepath.Join
   100      description: |
   101        Joins any number of path elements into a single path, adding a separator if necessary.
   102  
   103        A wrapper for Go's [`filepath.Join`](https://golang.org/pkg/path/filepath/#Join) function.
   104      arguments:
   105        - name: elem...
   106          required: true
   107          description: The path elements to join (0 or more)
   108      examples:
   109        - |
   110          $ gomplate -i '{{ filepath.Join "/tmp" "foo" "bar" }}'
   111          /tmp/foo/bar
   112          C:\> gomplate.exe -i '{{ filepath.Join "C:\tmp" "foo" "bar" }}'
   113          C:\tmp\foo\bar
   114    - name: filepath.Match
   115      description: |
   116        Reports whether name matches the shell file name pattern.
   117  
   118        A wrapper for Go's [`filepath.Match`](https://golang.org/pkg/path/filepath/#Match) function.
   119      arguments:
   120        - name: pattern
   121          required: true
   122          description: The pattern to match on
   123        - name: path
   124          required: true
   125          description: The path to match
   126      examples:
   127        - |
   128          $ gomplate -i '{{ filepath.Match "*.csv" "foo.csv" }}'
   129          true
   130    - name: filepath.Rel
   131      description: |
   132        Returns a relative path that is lexically equivalent to targetpath when joined to basepath with an intervening separator.
   133  
   134        A wrapper for Go's [`filepath.Rel`](https://golang.org/pkg/path/filepath/#Rel) function.
   135      arguments:
   136        - name: basepath
   137          required: true
   138          description: The base path
   139        - name: targetpath
   140          required: true
   141          description: The target path
   142      examples:
   143        - |
   144          $ gomplate -i '{{ filepath.Rel "/a" "/a/b/c" }}'
   145          b/c
   146    - name: filepath.Split
   147      description: |
   148        Splits path immediately following the final path separator, separating it into a directory and file name component.
   149  
   150        The function returns an array with two values, the first being the diretory, and the second the file.
   151  
   152        A wrapper for Go's [`filepath.Split`](https://golang.org/pkg/path/filepath/#Split) function.
   153      pipeline: true
   154      arguments:
   155        - name: path
   156          required: true
   157          description: The input path
   158      examples:
   159        - |
   160          $ gomplate -i '{{ $p := filepath.Split "/tmp/foo" }}{{ $dir := index $p 0 }}{{ $file := index $p 1 }}dir is {{$dir}}, file is {{$file}}'
   161          dir is /tmp/, file is foo
   162          C:\> gomplate.exe -i '{{ $p := filepath.Split `C:\tmp\foo` }}{{ $dir := index $p 0 }}{{ $file := index $p 1 }}dir is {{$dir}}, file is {{$file}}'
   163          dir is C:\tmp\, file is foo
   164    - name: filepath.ToSlash
   165      description: |
   166        Returns the result of replacing each separator character in path with a slash (`/`) character.
   167  
   168        A wrapper for Go's [`filepath.ToSlash`](https://golang.org/pkg/path/filepath/#ToSlash) function.
   169      pipeline: true
   170      arguments:
   171        - name: path
   172          required: true
   173          description: The input path
   174      examples:
   175        - |
   176          $ gomplate -i '{{ filepath.ToSlash "/foo/bar" }}'
   177          /foo/bar
   178          C:\> gomplate.exe -i '{{ filepath.ToSlash `foo\bar\baz` }}'
   179          foo/bar/baz
   180    - name: filepath.VolumeName
   181      description: |
   182        Returns the leading volume name. Given `C:\foo\bar` it returns `C:` on Windows. Given a UNC like `\\host\share\foo` it returns `\\host\share`. On other platforms it returns an empty string.
   183  
   184        A wrapper for Go's [`filepath.VolumeName`](https://golang.org/pkg/path/filepath/#VolumeName) function.
   185      pipeline: true
   186      arguments:
   187        - name: path
   188          required: true
   189          description: The input path
   190      examples:
   191        - |
   192          C:\> gomplate.exe -i 'volume is {{ filepath.VolumeName "C:/foo/bar" }}'
   193          volume is C:
   194          $ gomplate -i 'volume is {{ filepath.VolumeName "/foo/bar" }}'
   195          volume is