Print formats the interface with the JSONPath Template.
(ios *iostreams.IOStreams, data interface{})
| 29 | |
| 30 | // Print formats the interface with the JSONPath Template. |
| 31 | func (j *JSONPathPrinter) Print(ios *iostreams.IOStreams, data interface{}) error { |
| 32 | err := j.JSONPath.Execute(ios.Out, data) |
| 33 | if err == nil { |
| 34 | _, _ = ios.Out.Write([]byte("\n")) |
| 35 | } else { |
| 36 | buf := bytes.NewBuffer(nil) |
| 37 | fmt.Fprintf(buf, "Error executing template: %v. Printing more information for debugging the template:\n", err) |
| 38 | fmt.Fprintf(buf, "\ttemplate was:\n\t\t%v\n", j.rawTemplate) |
| 39 | fmt.Fprintf(buf, "\tobject given to jsonpath engine was:\n\t\t%#v\n\n", data) |
| 40 | return fmt.Errorf("error executing jsonpath %q: %v", j.rawTemplate, buf.String()) |
| 41 | } |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | // AllowMissingKeys tells the template engine if missing keys are allowed. |
| 46 | func (j *JSONPathPrinter) AllowMissingKeys(allow bool) { |