🌱
Sprout
Github
  • About
  • Roadmap to Sprout v1.0
  • Migration from Sprig
  • Introduction
    • Getting Started
    • Templating Conventions
  • Features
    • Loader System (Registry)
    • Loader System (Registry Group)
    • Function Aliases
    • Function Notices
    • Safe Functions
  • Registries
    • List of all registries
    • Backward
    • Checksum
    • Conversion
    • Crypto
    • Encoding
    • Env
    • Filesystem
    • Maps
    • Numeric
    • Network
    • Random
    • Reflect
    • Regexp
    • SemVer
    • Slices
    • Std
    • Strings
    • Time
    • Uniqueid
  • Groups
    • List of all registry groups
    • All
    • Hermetic
  • Advanced
    • How to create a handler
    • How to create a registry
    • How to create a registry group
  • Links
    • GitHub repository
Powered by GitBook
On this page
  • pathBase
  • pathDir
  • pathExt
  • pathClean
  • pathIsAbs
  • osBase
  • osDir
  • osExt
  • osClean
  • osIsAbs
Edit on GitHub
  1. Registries

Filesystem

The Filesystem registry allows for efficient interaction with the file system, providing functions to read, write, and manipulate files directly from your templates.

You can easily import all the functions from the filesystem registry by including the following import statement in your code

import "github.com/go-sprout/sprout/registry/filesystem"

pathBase

The function returns the last element of a given path, effectively extracting the file or directory name from the full path.

Signature

{{ "/path/to/file.txt" | pathBase }} // Output: "file.txt"

pathDir

The function returns all but the last element of a given path, effectively extracting the directory portion of the path.

Signature

{{ "/" | pathDir }} // Output: "/"
{{ "/path/to/file.txt" | pathDir }} // Output: "/path/to"

pathExt

The function returns the file extension of the given path, identifying the type of file by its suffix.

Signature

{{ "/" | pathExt }} // Output: ""
{{ "/path/to/file.txt" | pathExt }} // Output: ".txt"

pathClean

The function cleans up a given path by simplifying any redundancies, such as removing unnecessary double slashes or resolving "." and ".." elements, resulting in a standardized and more straightforward path.

Signature

{{ "/path//to/file.txt" | pathClean }} // Output: "/path/to/file.txt"

pathIsAbs

The function checks whether the given path is an absolute path, returning true if it is and false if it is not.

Signature

{{ "/path/to/file.txt" | pathIsAbs }} // Output: true
{{ "../file.txt" | pathIsAbs }} // Output: false

osBase

The function returns the last element of a given path, using the operating system's specific path separator to determine the path structure.

Signature

{{ "C:\\path\\to\\file.txt" | osBase }} // Output(will be different): "file.txt"

osDir

The function returns all but the last element of a given path, using the operating system's specific path separator to navigate the directory structure.

Signature

{{ "C:\\path\\to\\file.txt" | osDir }} // Output(will be different): "C:\\path\\to"

osExt

The function returns the file extension of a given path, using the operating system's specific path separator to accurately determine the extension.

Signature

{{ "C:\\path\\to\\file.txt" | osExt }} // Output: ".txt"

osClean

The function cleans up a given path, using the operating system's specific path separator to simplify redundancies and standardize the path structure.

Signature

{{ "C:\\path\\\\to\\file.txt" | osClean }} // Output(will be different): "C:\\path\\to\\file.txt"

osIsAbs

The function checks whether the given path is absolute, using the operating system's specific path separator to determine if the path is absolute or relative.

Signature

{{ "C:\\path\\to\\file.txt" | osIsAbs }} // Output(will be different): true
PreviousEnvNextMaps

Last updated 5 months ago

PathBase(str string) string
PathDir(str string) string
PathExt(str string) string
PathClean(str string) string
PathIsAbs(str string) bool
OsBase(str string) string
OsDir(str string) string
OsExt(str string) string
OsClean(str string) string
OsIsAbs(str string) bool