2018-05-31 10:51:50 +00:00
![](https://badges.fyi/github/license/Luzifer/korvike)
![](https://badges.fyi/github/downloads/Luzifer/korvike)
![](https://badges.fyi/github/latest-release/Luzifer/korvike)
2016-07-31 20:17:50 +00:00
2016-07-31 19:19:17 +00:00
# Luzifer / korvike
`korvike` is the finnish translation to the word "replacer" and that is what it does: It takes a Go template and executes it.
## Available functions
2024-02-29 14:37:29 +00:00
Starting with `v1.0.0` Korvike is based on the [sprig functions collection ](https://masterminds.github.io/sprig/ ) with some additions:
2017-04-17 18:43:43 +00:00
- `{{ .<variable name> }}`
Take key-value pairs from the CLI and replace them inside the template
2018-05-31 10:54:58 +00:00
```console
$ echo "{{ .foo }}" | korvike -v foo=bar
2017-04-17 18:43:43 +00:00
bar
```
2024-02-29 16:55:20 +00:00
- `{{ file <file name> }}` / `{{ mustFile <file name> }}`
Read a file and place it inside the template, `file` returns an empty string on error, `mustFile` an error
2018-05-31 10:54:58 +00:00
```console
$ echo "Hello World" > hello
$ echo '{{ file "hello" }}' | korvike
2017-04-17 18:43:43 +00:00
Hello World
```
2020-04-08 20:38:16 +00:00
- `{{ markdown <source> }}`
Format the source using a markdown parser
```console
2021-04-11 21:45:58 +00:00
$ echo '{{ markdown "# headline" }}' | korvike
2020-04-08 20:38:16 +00:00
< h1 > headline< / h1 >
```
2021-03-22 15:22:23 +00:00
- `{{ tplexec (file "my.tpl") }}`
Execute the given template with the same function set and variables as the parent template.
```console
$ export FOO=bar
$ echo '{{ env "FOO" }}' >my.tpl
$ echo '{{ tplexec (file "my.tpl") }}' | korvike
bar
```
2021-12-10 16:54:28 +00:00
- `{{ urlescape <input string> }}`
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
```
2024-02-29 16:55:20 +00:00
- `{{ vault <path> <key> }}` / `{{ mustVault <path> <key> }}`
Read a key from Vault using `VAULT_ADDR` and `VAULT_TOKEN` environment variables (or `~/.vault-token` file) for authentication. `vault` returns an empty string on error, `mustVault` an error
2018-05-31 10:54:58 +00:00
```console
$ vault write secret/test foo=bar
$ echo '{{ vault "secret/test" "foo" }}' | korvike
2017-06-20 09:24:02 +00:00
bar
```