1
0
Fork 0
mirror of https://github.com/Luzifer/korvike.git synced 2024-11-09 16:00:09 +00:00
korvike/README.md
Knut Ahlers bea23f0bf1
Add basic string manipulation join and split
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2022-03-30 21:10:35 +02:00

3.2 KiB

Go Report Card

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

  • {{ .<variable name> }}
    Take key-value pairs from the CLI and replace them inside the template
    $ echo "{{ .foo }}" | korvike -v foo=bar
    bar
    
  • {{ b64decode <string> }}
    Decodes the string with base64 StdEncoding
    $ echo '{{ b64decode "SGVsbG8gV29ybGQ=" }}' | korvike
    Hello World
    
  • {{ b64encode <string> }}
    Encodes the string with base64 StdEncoding
    $ echo '{{ b64encode "Hello World" }}' | korvike
    SGVsbG8gV29ybGQ=
    
  • {{ env <variable name> [default value] }}
    Read environment variables and replace them inside the template
    $ export FOO=bar
    $ echo '{{ env "FOO" }}' | korvike
    bar
    
  • {{ file <file name> [default value] }}
    Read a file and place it inside the template
    $ echo "Hello World" > hello
    $ echo '{{ file "hello" }}' | korvike
    Hello World
    
  • {{ hash <algo> <string> }}
    Hash string with given algorithm (supported algorithms: md5, sha1, sha256, sha512)
    $ echo '{{ hash "sha256" "this is a test" }}' | korvike
    2e99758548972a8e8822ad47fa1017ff72f06f3ff6a016851f45c398732bc50c
    
  • {{ join <string> <delim> }}
    Joins the given slice of strings with given delimiter.
    $ echo '{{ join (split "a,b,c" ",") "|" }}' | korvike
    a|b|c
    
  • {{ markdown <source> }}
    Format the source using a markdown parser
    $ echo '{{ markdown "# headline" }}' | korvike
    <h1>headline</h1>
    
  • {{ now <format string> }}
    Format the current date into the template (uses Go time format)
    $ echo '{{ now "2006-01-02 15:04:05" }}' | korvike
    2017-04-17 16:27:34
    
  • {{ split <string> <sep> }}
    Splits the given string by given separator.
    $ echo '{{ range (split "a,b,c" ",") }}{{ . }} {{ end }}' | korvike
    a b c
    
  • {{ tplexec (file "my.tpl") }}
    Execute the given template with the same function set and variables as the parent template.
    $ export FOO=bar
    $ echo '{{ env "FOO" }}' >my.tpl
    $ echo '{{ tplexec (file "my.tpl") }}' | korvike
    bar
    
  • {{ urlescape <input string> }}
    Do an URL escape to use the input string inside an query parameter in an URL
    $ echo '{{ urlescape "Hellö Wörld@Golang" }}' | korvike 
    Hell%C3%B6+W%C3%B6rld%40Golang
    
  • {{ vault <path> <key> [default value] }}
    Read a key from Vault using VAULT_ADDR and VAULT_TOKEN environment variables (or ~/.vault-token file) for authentication.
    $ vault write secret/test foo=bar
    $ echo '{{ vault "secret/test" "foo" }}' | korvike
    bar