Documentation ¶
Index ¶
- Variables
- func EnvFileFunc(receiverFunc EnvFileReceiverFunc) map[string]any
- func New(name string, funcs ...map[string]any) (tpl *template.Template)
- func PrivateTempFile(name string) (filename string, err error)
- func TempDir() string
- func TempFile(name string) (filename string)
- func TemplateFuncs(funcs ...map[string]any) (templateFuncs map[string]any)
- type DefaultData
- type EnvFileReceiverFunc
Constants ¶
This section is empty.
Variables ¶
var NotStrictlyPrivate = errors.New("the private temp file is not strictly accessible by owners only")
NotStrictlyPrivate indicates that a PrivateTempFile was successfully created but the OS reports that it can be accessed by others
Functions ¶
func EnvFileFunc ¶ added in v0.27.0
func EnvFileFunc(receiverFunc EnvFileReceiverFunc) map[string]any
EnvFileFunc creates a template func to retrieve a profile .env file that can be used to pass variables between shells
func PrivateTempFile ¶ added in v0.27.0
PrivateTempFile is like TempFile but guarantees that the returned file can be accessed by owners only when err is nil
func TempDir ¶
func TempDir() string
TempDir returns the volatile temporary directory that is returned by template function tempDir
func TempFile ¶
TempFile returns the volatile temporary file that is returned by template function tempFile
func TemplateFuncs ¶
TemplateFuncs declares a few standard functions to simplify working with templates
Available functions:
- {{ "some string" | contains "some" }} => true
- {{ "some string" | matches "^.+str.+$" }} => true
- {{ "some old string" | replace "old" "new" }} => "some new string"
- {{ "some old string" | replaceR "(old)" "$1 and new" }} => "some old and new string"
- {{ "some old string" | regex "(old)" "$1 and new" }} => "some old and new string" (alias to "replaceR")
- {{ "ABC" | lower }} => "abc"
- {{ "abc" | upper }} => "ABC"
- {{ " A " | trim }} => "A"
- {{ "--A-" | trimPrefix " " }} => "A-"
- {{ "--A-" | trimSuffix " " }} => "--A"
- {{ "A,B,C" | split "," }} => ["A", "B", "C"]
- {{ "A,B,C" | split "," | join ";" }} => "A;B;C"
- {{ "A ,B, C" | splitR "\\s*,\\s*" | join ";" }} => "A;B;C"
- {{ list "A" "B" "C" }} => ["A", "B", "C"]
- {{ with $v := map "k1" "v1" "k2" "v2" }} {{ .k1 }}-{{ .k2 }} {{ end }} => " v1-v2 "
- {{ with $v := list "A" "B" "C" "D" | map }} {{ ._0 }}-{{ ._1 }}-{{ ._3 }} {{ end }} => " A-B-D "
- {{ with $v := list "A" "B" "C" "D" | map "key" }} {{ .key | join "-" }} {{ end }} => " A-B-C-D "
- {{ "plain" | hex }} => "706c61696e"
- {{ "plain" | base64 }} => "cGxhaW4="
- {{ tempDir }} => "/path/to/unique-tempdir"
- {{ tempFile "filename" }} => "/path/to/unique-tempdir/filename"
Types ¶
type DefaultData ¶
type DefaultData struct { Now time.Time CurrentDir string StartupDir string TempDir string BinaryDir string Hostname string OS string Arch string Env map[string]string }
DefaultData provides default variables for templates
func NewDefaultData ¶
func NewDefaultData(env map[string]string) (data DefaultData)
NewDefaultData returns an initialized DefaultData
func (*DefaultData) InitDefaults ¶
func (d *DefaultData) InitDefaults()
InitDefaults initializes DefaultData if not yet initialized
type EnvFileReceiverFunc ¶ added in v0.27.0
EnvFileReceiverFunc declares the backend interface for the "{{env}}" template function