diff --git a/README.md b/README.md index 88c18d3..e2e2bd9 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ # echo "{{ .foo }}" | korvike -v foo=bar bar ``` +- `{{ b64encode }}` + Encodes the string with base64 [StdEncoding](https://golang.org/pkg/encoding/base64/#pkg-variables) + ```console + # echo '{{ b64encode "Hello World" }}' | korvike + SGVsbG8gV29ybGQ= + ``` - `{{ env [default value] }}` Read environment variables and replace them inside the template ```bash diff --git a/functions/func_base64.go b/functions/func_base64.go new file mode 100644 index 0000000..86dc7df --- /dev/null +++ b/functions/func_base64.go @@ -0,0 +1,9 @@ +package functions + +import "encoding/base64" + +func init() { + registerFunction("b64encode", func(name string, v ...string) string { + return base64.StdEncoding.EncodeToString([]byte(name)) + }) +}