MCPcopy Create free account
hub / github.com/goadesign/goa / Read

Method Read

codegen/template/reader.go:17–43  ·  view source on GitHub ↗

Read returns the template with the given name, optionally including partials. Partials are loaded from the 'partial' subdirectory and defined as named blocks.

(name string, partials ...string)

Source from the content-addressed store, hash-verified

15// Read returns the template with the given name, optionally including partials.
16// Partials are loaded from the 'partial' subdirectory and defined as named blocks.
17func (tr *TemplateReader) Read(name string, partials ...string) string {
18 var prefix string
19 if len(partials) > 0 {
20 partialDefs := make([]string, 0, len(partials))
21 for _, partial := range partials {
22 content, err := fs.ReadFile(tr.FS, path.Join("templates", "partial", partial+".go.tpl"))
23 if err != nil {
24 panic(fmt.Sprintf("failed to read partial template %s: %v", partial, err))
25 }
26 // Normalize line endings
27 contentStr := strings.ReplaceAll(string(content), "\r\n", "\n")
28 partialDefs = append(partialDefs,
29 fmt.Sprintf("{{- define \"partial_%s\" }}\n%s{{- end }}", partial, contentStr))
30 }
31 prefix = strings.Join(partialDefs, "\n")
32 }
33 content, err := fs.ReadFile(tr.FS, path.Join("templates", name)+".go.tpl")
34 if err != nil {
35 panic(fmt.Sprintf("failed to load template %s: %v", name, err))
36 }
37 // Normalize line endings to ensure consistent template parsing across platforms
38 contentStr := strings.ReplaceAll(string(content), "\r\n", "\n")
39 if prefix != "" {
40 return prefix + "\n" + contentStr
41 }
42 return contentStr
43}

Callers 15

HeaderFunction · 0.45
initFunction · 0.45
initFunction · 0.45
exampleSvrMainFunction · 0.45
exampleCLIMainFunction · 0.45
ConvertFileFunction · 0.45
ViewsFileFunction · 0.45
FilesFunction · 0.45
interceptorFileFunction · 0.45
wrapperFileFunction · 0.45
service_data.goFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected