Skip to content

Commit

Permalink
template functions: add sprig template library v3
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrode committed Sep 28, 2021
1 parent 01d0532 commit f80c638
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ The content of the request and response file are execatly the same as if you wou

# Template functions

> **apitest** supports the [Sprig template](http://masterminds.github.io/sprig/) function library in v3. Internally provided functions like `add` overwrite the `Sprig` function.
As described before, if you use an external file you can make use of so called template functions. What they are and how they work for the apitesting tool is described in the following part.

Template Functions are invoked using the tags `{{ }}` and upon returning substitutes the function call with
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ module github.com/programmfabrik/apitest
go 1.13

require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/clbanning/mxj v1.8.4
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/mattn/go-sqlite3 v1.14.8
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/moul/http2curl v1.0.0
github.com/pkg/errors v0.9.1
github.com/programmfabrik/go-test-utils v0.0.0-20191114143449-b8e16b04adb1
Expand Down
2 changes: 2 additions & 0 deletions pkg/lib/template/template_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/pkg/errors"
"github.com/programmfabrik/apitest/pkg/lib/datastore"
"golang.org/x/mod/semver"
Expand Down Expand Up @@ -445,6 +446,7 @@ func (loader *Loader) Render(
tmpl, err := template.
New("tmpl").
Delims(loader.Delimiters.Left, loader.Delimiters.Right).
Funcs(sprig.TxtFuncMap()).
Funcs(funcMap).
Parse(string(tmplBytes))
if err != nil {
Expand Down

0 comments on commit f80c638

Please sign in to comment.