Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFuncMap ¶
GetFuncMap returns the list of functions provided by sprig. It adds the functions "toTime", "formatTime", "parseTime", "mustParseTime", "toTimeLayout" and changes the function "fail".
The "toTime" function receives a time or a Unix epoch and returns a time.Time in UTC. The "formatTime" function uses "toTime" and formats the resulting time using RFC3339. The functions "parseTime" and "mustParseTime" parse a string and return the time.Time it represents. The "toTimeLayout" function converts strings like "time.RFC3339" or "UnixDate" to the actual layout represented by the Go constant with the same name. The "fail" function sets the provided message, so that template errors are reported directly to the template without having the wrapper that text/template adds.
{{ toTime }} => time.Now().UTC() {{ .Token.nbf | toTime }} => time.Unix(.Token.nbf, 0).UTC() {{ .Token.nbf | formatTime }} => time.Unix(.Token.nbf, 0).UTC().Format(time.RFC3339) {{ "2024-07-02T23:16:02Z" | parseTime }} => time.Parse(time.RFC3339, "2024-07-02T23:16:02Z") {{ parseTime "time.RFC339" "2024-07-02T23:16:02Z" }} => time.Parse(time.RFC3339, "2024-07-02T23:16:02Z") {{ parseTime "time.UnixDate" "Tue Jul 2 16:20:48 PDT 2024" "America/Los_Angeles" }} => loc, _ := time.LoadLocation("America/Los_Angeles") time.ParseInLocation(time.UnixDate, "Tue Jul 2 16:20:48 PDT 2024", loc) {{ toTimeLayout "RFC3339" }} => time.RFC3339
sprig "env" and "expandenv" functions are removed to avoid the leak of information.
func ValidateTemplate ¶
ValidateTemplate validates a text template results in valid JSON when it's executed with empty template data. If template execution results in invalid JSON, the template is invalid. When the template is valid, it can be used safely. A valid template can still result in invalid JSON when non-empty template data is provided.
func ValidateTemplateData ¶
ValidateTemplateData validates that template data is valid JSON.
Types ¶
This section is empty.