(templateType TemplateType, templateNameOrContent string, in any)
| 81 | } |
| 82 | |
| 83 | func (tc *templateCache) evaluateTemplate(templateType TemplateType, templateNameOrContent string, in any) (string, error) { |
| 84 | tc.mu.Lock() |
| 85 | defer tc.mu.Unlock() |
| 86 | |
| 87 | tc.initializeTemplateMapKey(templateType) |
| 88 | m, ok := tc.templates[templateType][templateNameOrContent] |
| 89 | if !ok { |
| 90 | // return "", fmt.Errorf("template not loaded: %s", templateName) |
| 91 | loadErr := tc.loadTemplateIfExists(templateType, templateNameOrContent) |
| 92 | if loadErr != nil { |
| 93 | return "", loadErr |
| 94 | } |
| 95 | m = tc.templates[templateType][templateNameOrContent] // ok is not important since we check m on the next line, and wealready checked |
| 96 | } |
| 97 | if m == nil { |
| 98 | return "", fmt.Errorf("failed loading a template for %s", templateNameOrContent) |
| 99 | } |
| 100 | |
| 101 | var buf bytes.Buffer |
| 102 | |
| 103 | if err := m.Execute(&buf, in); err != nil { |
| 104 | return "", err |
| 105 | } |
| 106 | return buf.String(), nil |
| 107 | } |
no test coverage detected