NewTemplateInspectorFromString creates a new TemplateInspector from a string which is compiled into a template.
(out io.Writer, tmplStr string)
| 46 | // NewTemplateInspectorFromString creates a new TemplateInspector from a string |
| 47 | // which is compiled into a template. |
| 48 | func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, error) { |
| 49 | if out == nil { |
| 50 | return nil, errors.New("no output stream") |
| 51 | } |
| 52 | if tmplStr == "" { |
| 53 | return NewIndentedInspector(out), nil |
| 54 | } |
| 55 | |
| 56 | if tmplStr == "json" { |
| 57 | return NewJSONInspector(out), nil |
| 58 | } |
| 59 | |
| 60 | tmpl, err := templates.Parse(tmplStr) |
| 61 | if err != nil { |
| 62 | return nil, fmt.Errorf("template parsing error: %w", err) |
| 63 | } |
| 64 | return NewTemplateInspector(out, tmpl), nil |
| 65 | } |
| 66 | |
| 67 | // GetRefFunc is a function which used by Inspect to fetch an object from a |
| 68 | // reference |
searching dependent graphs…