loadTemplatesFromFS is a helper function that loads templates from the given filesystem and directory. It returns an error if reading the directory or parsing any template fails.
(fsys fs.FS, dir string)
| 80 | // loadTemplatesFromFS is a helper function that loads templates from the given filesystem and directory. |
| 81 | // It returns an error if reading the directory or parsing any template fails. |
| 82 | func loadTemplatesFromFS(fsys fs.FS, dir string) error { |
| 83 | tmplFiles, err := fs.ReadDir(fsys, dir) |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | |
| 88 | pattern := dir + "/" |
| 89 | if dir == "." { |
| 90 | pattern = "" |
| 91 | } |
| 92 | |
| 93 | for _, tmpl := range tmplFiles { |
| 94 | if tmpl.IsDir() { |
| 95 | continue |
| 96 | } |
| 97 | |
| 98 | pt, err := template.ParseFS(fsys, pattern+tmpl.Name()) |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | |
| 103 | templates[tmpl.Name()] = pt |
| 104 | } |
| 105 | return nil |
| 106 | } |
no outgoing calls
no test coverage detected