ParseText parse template.
Define struct
type Data struct {
Name string
Value string
}
Define func want to trigger
type TestFn struct {
}
func (self *TestFn) Call(body string) string {
fmt.Println("mock call function")
return body
}
How to use
test := new(TestFn)
data := Data{
Name: "Nguyen Cat Pham",
Value: "oscar",
}
obj := map[string]interface{}{
"data": data,
"fn": test,
}
strParsing := `{{$x := printf "{\"serial\":%q}" "response data" }}{{.fn.Call $x}}`
result, err := ParseText("test", strParsing, obj)
if err != nil || result == "" {
// handle error here
}
Request handler requires Go v1.11+ to run.
Install the package.
$ go get github.com/onskycloud/exprSee KUBERNETES.md
- Write MORE Tests
- Add Night Mode
MIT