Skip to content

Commit

Permalink
Handle errors in prettyPrint HTTP templating function
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Jul 22, 2024
1 parent 27e5f8f commit a16dfc9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/target/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@ func loadRequestTemplate(templateFile string) (int, *template.Template, error) {
func parseRequestTemplate(templateContent string) (*template.Template, error) {
customTemplateFunctions := template.FuncMap{
// If you use this in your template on struct-like fields, you get rendered nice JSON `{"field":"value"}` instead of stringified map `map[field:value]`
"prettyPrint": func(v interface{}) string {
a, _ := json.Marshal(v)
return string(a)
"prettyPrint": func(v interface{}) (string, error) {
bytes, err := json.Marshal(v)
if err != nil {
return "", err
}
return string(bytes), nil
},
"env": func(name string) string {
return os.Getenv(name)
Expand Down

0 comments on commit a16dfc9

Please sign in to comment.