From 2fd0bf97a1fd2306cdb391c74f4e35af0b14102f Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 31 May 2018 12:50:34 +0200 Subject: [PATCH] Add b64encode as a function Signed-off-by: Knut Ahlers --- README.md | 6 ++++++ functions/func_base64.go | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 functions/func_base64.go 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)) + }) +}