This website is running only from the browser and it uses go templates on WASM to render the templates.
Below are some examples of Go templates and functions available in this environment.
Get basic knowledge from https://pkg.go.dev/text/template
Iterate over a slice and print each element.
{{ range $index, $element := .data.items }}
{{- mustToPrettyJson $element }}
{{ end }} data:
items:
- id: 1
name: John
- id: 2
name: Jane {
"id": 1,
"name": "John"
}
{
"id": 2,
"name": "Jane"
}
Check functions eq, ne, lt, le, gt, ge but arguments should be comparable types and result is boolean.
{{if eq (int .result) 10 -}}
Result is 10
{{- else if eq (int .result) 0 -}}
Result is 0
{{- else -}}
unknown
{{- end}} data:
result: 10 Result is 10Generates a sequence of integers from 0 up to (but not including) the given number.
{{ range $x := 5 }}
{{- $x }}
{{ end }} 0
1
2
3
4Use with to limit the scope of a variable inside of a template. If we want to reach outer scope, we can use $. syntax.
{{ with .name -}}
Name {{ .user }}; outer value is {{ $.value }}
{{- end }} name:
user: "Xavier"
value: 10 Name Xavier; outer value is 10Define and use variables in templates.
{{- $greeting := "Hello" -}}
{{- $name := .name -}}
{{ $greeting }}, {{ $name }}! name: "Alice" Hello, Alice!Access elements in arrays, slices, or maps by index or key.
{{- $firstItem := index .items 0 -}}
First item: {{ $firstItem }} items: ["apple", "banana", "cherry"] First item: appleComments are ignored during template execution.
{{/* This is a comment and will be ignored */ -}} Nested template definition. https://pkg.go.dev/text/template#hdr-Nested_template_definitions
{{- define "mytemplate" }}Hello, {{ .name }}!{{ end -}}
{{ template "mytemplate" . }} name: "World" Hello, World!Renders a template string with the given context.
{{ tpl "Hello, {{ .name }}!" . }} name: "World" Hello, World!Renders a named template with the given context.
{{ include "mytemplate" . }} Fails if the given value is empty.
{{ required "Value is required" .value }} value: "" program fail, exit code 1Encodes a value to TOML string.
{{ toToml .data }} Encodes a value to YAML string.
{{ toYaml .data }} Decodes a YAML string to a value.
{{ fromYaml "name: John\nage: 30" }} Decodes a YAML string to an array.
{{ fromYamlArray "- item1\n- item2\n- item3" }} Decodes a JSON array string.
{{ fromJsonArray "[1,2,3]" }} {{ abbrev 10 "Hello World" }} Hello W...{{ abbrevboth 5 10 "1234 5678 9123" }} ...5678...{{ add 1 2 3 4 5 }} 15{{ add1 1 }} 2{{ add1f 1.1 }} 2.1{{ addf 1.1 2.2 3.3 4.4 5.5 }} 16.5{{ adler32sum "Hello World" }} 403375133Timestamp to human readable time ago.
{{ ago 1687989601 }} 11s{{ all true true false }} false{{ any true true false }} trueFirst argument must be a slice.
{{ append . "add" }} [1 add]{{ atoi "123" }} 123{{ b32dec "MZXW6YTBOI======" }} foobar{{ b32enc "foobar" }} MZXW6YTBOI======{{ b64dec "SGVsbG8gV29ybGQ=" }} Hello World{{ b64enc "Hello World" }} SGVsbG8gV29ybGQ=path.Base function.
{{ base "/foo/bar/baz.js" }} baz.jsgolang.org/x/crypto/bcrypt package's GenerateFromPassword function.
{{ bcrypt "Hello World" }} $2a$10$dTu/HetKKYglHR1bs9mBFeGkOFgIMAabTdC0TNPh5ucVJLQLTfVYG{{ biggest 1 2 3 4 5 }} 5 {{ camelcase "hello_world" }} HelloWorld{{ cat "Hello" "World" }} Hello World{{ ceil 1.1 }} 2{{ chunk 2 (list 1 2 3 4 5) }} [[1 2] [3 4] [5]]path.Clean function.
{{ clean "/foo/bar/.." }} /fooReturns the first non-empty value.
{{ coalesce "" "Hello World" }} Hello WorldRemoves nil/empty values from a list.
{{ list 1 "" nil 2 | compact }} [1 2]Concatenates multiple lists into one.
{{ list 1 2 | concat (list 3 4) }} [1 2 3 4]strings.Contains function but arguments are reversed.
{{ contains "World" "Hello World" }} trueDate can be a time.Time or an int, int32, int64.
{{ date "2006-01-02" 1690151142 }} 2023-07-24Format a date in a specific timezone.
{{ dateInZone "2006-01-02" 1690151142 "UTC" }} 2023-07-24Modifies a time.Time by a duration string.
{{ dateModify "2h" now }} Modifies a time.Time by a duration string in a specific timezone.
{{ dateInZone "2h" now "UTC" }} Alias for dateModify.
Decrypts text with AES-256 GCM.
Creates a deep copy of a value.
{{ deepCopy . }} Tests for deep equality between two values.
{{ deepEqual .a .b }} Returns default value if given value is empty.
{{ .value | default "default value" }} default valueDerives a password using the Master Password algorithm.
{{ dict "a" 1 "b" 2 }} map[a:1 b:2]Traverses nested maps/objects using a path.
{{ dig "user" "name" "default" . }} path.Dir function.
{{ dir "/foo/bar/baz.js" }} /foo/barInteger division.
{{ div 10 2 }} 5Float division.
{{ divf 10 3 }} 3.333333{{ duration "3600" }} 1h0m0sRounds duration to the most significant unit.
{{ durationRound "3h45m" }} 4h{{ empty "" }} trueEncrypts text with AES-256 GCM.
Disabled in Helm for security reasons.
{{ env "HOME" }} /home/rytshDisabled in Helm for security reasons.
{{ expandenv "$HOME" }}
{{ expandenv "${USER}" }} /home/rytsh
rytshpath.Ext function.
{{ ext "/foo/bar/baz.js" }} .js{{ fail "FAILED PROGRAM" }} program fail, exit code 1Returns the first item of a list.
{{ list 1 2 3 | first }} 1Converts to float64.
{{ "3.14" | float64 }} 3.14Returns the floor of a float.
{{ 3.7 | floor }} 3Decodes a JSON string.
{{ fromJson "{\"name\":\"John\"}" }} Generates a new self-signed CA certificate.
Generates a CA certificate with a given private key.
Generates a private key (rsa, dsa, ecdsa, ed25519).
{{ genPrivateKey "rsa" }} Generates a self-signed certificate.
Generates a self-signed certificate with a given key.
Generates a certificate signed by a CA.
Generates a certificate signed by a CA with a given key.
Gets a value from a map by key.
{{ get .data "key" }} data:
key: "value" valueResolves hostname to IP address.
Tests whether a list contains an element.
{{ list 1 2 3 | has 2 }} trueTests whether a map contains a key.
{{ hasKey .data "name" }} data:
name: "Ada" trueTests whether a string has a prefix.
{{ hasPrefix "Hello" "Hello World" }} trueTests whether a string has a suffix.
{{ hasSuffix "World" "Hello World" }} trueReturns 'Hello!'.
{{ hello }} Hello!Formats a date for HTML date input.
{{ now | htmlDate }} Formats a date for HTML date input in a timezone.
Generates bcrypt hash for htpasswd.
{{ htpasswd "username" "password" }} Indents every line with the given number of spaces.
{{ .text | indent 4 }} text: |-
line1
line2 line1
line2Returns all but the last item of a list.
{{ list 1 2 3 4 | initial }} [1 2 3]Returns the initials of a name.
{{ initials "John Doe" }} JDConverts to int.
{{ "123" | int }} 123Converts to int64.
{{ "123" | int64 }} 123Checks if a path is absolute.
{{ isAbs "/foo/bar" }} trueJoins a list with a separator.
{{ list "a" "b" "c" | join "-" }} a-b-cConverts to kebab-case.
{{ kebabcase "HelloWorld" }} hello-worldReturns the keys of a map.
{{ keys .data }} data:
name: "Alice"
age: 30 [name age]Tests if a value is of a specific kind.
{{ kindIs "int" 123 }} trueReturns the kind of a value.
{{ kindOf 123 }} intReturns the last item of a list.
{{ list 1 2 3 | last }} 3Creates a list from arguments.
{{ list 1 2 3 }} [1 2 3]Converts to lowercase.
{{ "HELLO" | lower }} helloReturns the maximum integer.
{{ max 1 5 3 }} 5Returns the maximum float.
{{ maxf 1.1 5.5 3.3 }} 5.5Merges maps, giving precedence to the dest map.
{{ merge .dst .src }} Merges maps, giving precedence to the source map.
{{ mergeOverwrite .dst .src }} Returns the minimum integer.
{{ min 1 5 3 }} 1Returns the minimum float.
{{ minf 1.1 5.5 3.3 }} 1.1Returns the modulo.
{{ mod 10 3 }} 1Multiplies integers.
{{ mul 2 3 4 }} 24Multiplies floats.
{{ mulf 2.5 3.0 }} 7.5Appends to a list, returns error on failure.
Chunks a list, returns error on failure.
Compacts a list, returns error on failure.
Modifies a date, returns error on failure.
Deep copies a value, returns error on failure.
Gets first item, returns error on failure.
Decodes JSON, returns error on failure.
Checks list membership, returns error on failure.
Gets all but last item, returns error on failure.
Gets last item, returns error on failure.
Merges maps, returns error on failure.
Merges maps with overwrite, returns error on failure.
Prepends to a list, returns error on failure.
Pushes to a list, returns error on failure.
Finds regex match, returns error on failure.
Finds all regex matches, returns error on failure.
Tests regex match, returns error on failure.
Replaces all regex matches, returns error on failure.
Replaces all regex matches literally, returns error on failure.
Splits by regex, returns error on failure.
Gets all but first item, returns error on failure.
Reverses a list, returns error on failure.
Slices a list, returns error on failure.
Parses a date, returns error on failure.
Encodes to JSON, returns error on failure.
Encodes to pretty JSON, returns error on failure.
Encodes to raw JSON, returns error on failure.
Returns unique items, returns error on failure.
Filters out items, returns error on failure.
Alias for mustDateModify.
Indents with a newline prepended.
{{ "text" | nindent 4 }} Removes all whitespace.
{{ "hello world" | nospace }} helloworldReturns an empty string.
{{ nothing }} Returns the current time.
{{ now }} Removes keys from a map.
{{ omit .data "key1" "key2" }} Returns the last element of path (OS-specific).
{{ osBase "/foo/bar" }} Cleans a path (OS-specific).
{{ osClean "/foo//bar" }} Returns directory of path (OS-specific).
{{ osDir "/foo/bar/file.txt" }} Returns file extension (OS-specific).
{{ osExt "file.txt" }} Checks if path is absolute (OS-specific).
{{ osIsAbs "/foo/bar" }} Selects only specified keys from a map.
{{ pick .data "key1" "key2" }} Extracts a field from each map in a list.
{{ pluck "name" .users }} Returns singular or plural based on count.
{{ plural "cat" "cats" 2 }} catsPrepends an item to a list.
{{ list 2 3 | prepend 1 }} [1 2 3]Appends an item to a list.
{{ list 1 2 | push 3 }} [1 2 3]Wraps strings in double quotes and joins.
{{ list "a" "b" | quote }} "a" "b"Generates random alphabetic string.
{{ randAlpha 10 }} Generates random alphanumeric string.
{{ randAlphaNum 10 }} Generates random ASCII string.
{{ randAscii 10 }} Generates random bytes (base64 encoded).
Generates random int in range [min, max).
{{ randInt 1 100 }} Generates random numeric string.
{{ randNumeric 10 }} Finds first regex match.
{{ regexFind "[0-9]+" "abc123def" }} 123Finds all regex matches.
{{ regexFindAll "[0-9]+" "a1b2c3" -1 }} Tests if string matches regex.
{{ regexMatch "[0-9]+" "123" }} trueQuotes regex meta characters.
{{ regexQuoteMeta "a.b" }} a\\.bReplaces all regex matches.
{{ regexReplaceAll "[0-9]+" "a1b2" "X" }} aXbXReplaces all regex matches (literal replacement).
{{ regexReplaceAllLiteral "[0-9]+" "a1b2" "$1" }} a$1b$1Splits string by regex.
{{ regexSplit "[,;]" "a,b;c" -1 }} [a b c]Repeats a string n times.
{{ repeat 3 "ab" }} abababReplaces all occurrences.
{{ replace "o" "0" "hello" }} hell0Returns all but the first item.
{{ list 1 2 3 | rest }} [2 3]Reverses a list.
{{ list 1 2 3 | reverse }} [3 2 1]Rounds a float to n decimal places.
{{ round 3.14159 2 }} 3.14Parses a semantic version string.
{{ semver "1.2.3" }} Compares semantic versions.
{{ semverCompare "^1.2.0" "1.2.3" }} trueGenerates a sequence of integers.
{{ seq 1 5 }} 1 2 3 4 5Sets a key in a map.
{{ set .data "key" "value" }} Computes SHA1 hash.
{{ sha1sum "hello" }} Computes SHA256 hash.
{{ sha256sum "hello" }} Randomly shuffles a string.
{{ shuffle "hello" }} Returns a slice of a list.
{{ list 1 2 3 4 5 | slice 1 3 }} [2 3]Converts to snake_case.
{{ snakecase "HelloWorld" }} hello_worldSorts a list alphabetically.
{{ list "c" "a" "b" | sortAlpha }} [a b c]Splits string into a map.
{{ split "," "a,b,c" }} Splits string into a list.
{{ splitList "," "a,b,c" }} [a b c]Splits string into n parts.
{{ splitn "," 2 "a,b,c" }} Wraps strings in single quotes and joins.
{{ list "a" "b" | squote }} 'a' 'b'Subtracts integers.
{{ sub 5 3 }} 2Subtracts floats.
{{ subf 5.5 3.2 }} 2.3Returns substring from start to end.
{{ substr 0 5 "Hello World" }} HelloSwaps case of letters.
{{ swapcase "Hello" }} hELLOReturns first value if true, else second.
{{ ternary "yes" "no" true }} yesConverts to Title Case.
{{ title "hello world" }} Hello WorldParses a date string with format.
{{ toDate "2006-01-02" "2023-07-24" }} Converts to decimal integer.
{{ toDecimal 0x10 }} 16Encodes to JSON string.
{{ toJson .data }} Encodes to pretty JSON string.
{{ toPrettyJson .data }} Encodes to JSON without HTML escaping.
{{ toRawJson .data }} Converts to string.
{{ toString 123 }} 123Converts a list to strings.
{{ toStrings (list 1 2 3) }} Trims whitespace from both ends.
{{ trim " hello " }} helloTrims specified characters from both ends.
{{ trimAll "$" "$hello$" }} helloTrims prefix from string.
{{ trimPrefix "Mr. " "Mr. Smith" }} SmithTrims suffix from string.
{{ trimSuffix " Jr." "John Jr." }} JohnAlias for trimAll.
Truncates a string to n characters.
{{ trunc 5 "Hello World" }} HelloCreates an immutable list.
{{ tuple 1 2 3 }} Tests if value is of a specific type.
{{ typeIs "string" "hello" }} trueTests if value is like a specific type.
{{ typeIsLike "int" 123 }} Returns the type of a value.
{{ typeOf "hello" }} stringReturns unique items from a list.
{{ list 1 2 2 3 | uniq }} [1 2 3]Converts time to Unix timestamp.
{{ now | unixEpoch }} Removes a key from a map.
{{ unset .data "key" }} Generates a range from 0 to n-1.
{{ until 5 }} [0 1 2 3 4]Generates a range with step.
{{ untilStep 0 10 2 }} [0 2 4 6 8]Removes title case.
{{ untitle "Hello World" }} hello worldConverts to uppercase.
{{ upper "hello" }} HELLOJoins URL parts into a complete URL.
{{ urlJoin .urlParts }} Parses a URL into parts.
{{ urlParse "https://example.com/path" }} Generates a random UUID v4.
{{ uuidv4 }} Returns all values from a map.
{{ values .data }} Filters items out of a list.
{{ list 1 2 3 4 | without 2 4 }} [1 3]Wraps text at specified column width.
{{ wrap 10 "This is a long text" }} Wraps text with custom separator.
{{ wrapWith 10 "\n" "This is a long text" }}