processTemplate processes the template with the given name and data. It returns the resulting bytes.Buffer or an error if the template execution fails.
(name string, data map[string]any)
| 37 | // processTemplate processes the template with the given name and data. |
| 38 | // It returns the resulting bytes.Buffer or an error if the template execution fails. |
| 39 | func processTemplate(name string, data map[string]any) (*bytes.Buffer, error) { |
| 40 | t, ok := templates[name] |
| 41 | if !ok { |
| 42 | return nil, fmt.Errorf("template %s not found", name) |
| 43 | } |
| 44 | |
| 45 | var tpl bytes.Buffer |
| 46 | |
| 47 | if err := t.Execute(&tpl, data); err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | |
| 51 | return &tpl, nil |
| 52 | } |
| 53 | |
| 54 | // GetTemplateByString returns the parsed template as a string. |
| 55 | // It returns an error if the template processing fails. |
no outgoing calls