From 2b2aadc279b46d8c8de5b6d3d97d333d29459d36 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 10 Dec 2021 17:54:28 +0100 Subject: [PATCH] Add urlescape function Signed-off-by: Knut Ahlers --- README.md | 6 ++++++ functions/func_urlescape.go | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 functions/func_urlescape.go diff --git a/README.md b/README.md index 80aa13a..2f7484c 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,12 @@ $ echo '{{ tplexec (file "my.tpl") }}' | korvike bar ``` +- `{{ urlescape }}` + Do an URL escape to use the input string inside an query parameter in an URL + ```console + $ echo '{{ urlescape "Hellö Wörld@Golang" }}' | korvike + Hell%C3%B6+W%C3%B6rld%40Golang + ``` - `{{ vault [default value] }}` Read a key from Vault using `VAULT_ADDR` and `VAULT_TOKEN` environment variables (or `~/.vault-token` file) for authentication. ```console diff --git a/functions/func_urlescape.go b/functions/func_urlescape.go new file mode 100644 index 0000000..5d8681d --- /dev/null +++ b/functions/func_urlescape.go @@ -0,0 +1,7 @@ +package functions + +import "net/url" + +func init() { + registerFunction("urlescape", url.QueryEscape) +}