LoadTemplates loads all of our template files into a text/template. The path of template is relative to the templates directory.
(src embed.FS, t *template.Template)
| 1251 | // LoadTemplates loads all of our template files into a text/template. The |
| 1252 | // path of template is relative to the templates directory. |
| 1253 | func LoadTemplates(src embed.FS, t *template.Template) error { |
| 1254 | return fs.WalkDir(src, "templates", func(path string, d fs.DirEntry, err error) error { |
| 1255 | if err != nil { |
| 1256 | return fmt.Errorf("error walking directory %s: %w", path, err) |
| 1257 | } |
| 1258 | if d.IsDir() { |
| 1259 | return nil |
| 1260 | } |
| 1261 | |
| 1262 | buf, err := src.ReadFile(path) |
| 1263 | if err != nil { |
| 1264 | return fmt.Errorf("error reading file '%s': %w", path, err) |
| 1265 | } |
| 1266 | |
| 1267 | templateName := strings.TrimPrefix(path, "templates/") |
| 1268 | tmpl := t.New(templateName) |
| 1269 | _, err = tmpl.Parse(string(buf)) |
| 1270 | if err != nil { |
| 1271 | return fmt.Errorf("parsing template '%s': %w", path, err) |
| 1272 | } |
| 1273 | return nil |
| 1274 | }) |
| 1275 | } |
| 1276 | |
| 1277 | func OperationSchemaImports(s *Schema) (map[string]goImport, error) { |
| 1278 | res := map[string]goImport{} |
no outgoing calls