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

Function Files

codegen/service/service.go:17–268  ·  view source on GitHub ↗

Files returns the generated files for the given service as well as a map indexing user type names by custom path as defined by the "struct:pkg:path" metadata. The map is built over each invocation of Files to avoid duplicate type definitions.

(genpkg string, service *expr.ServiceExpr, services *ServicesData, userTypePkgs map[string][]string)

Source from the content-addressed store, hash-verified

15// metadata. The map is built over each invocation of Files to avoid duplicate
16// type definitions.
17func Files(genpkg string, service *expr.ServiceExpr, services *ServicesData, userTypePkgs map[string][]string) []*codegen.File {
18 svc := services.Get(service.Name)
19 svcName := svc.PathName
20 svcPath := filepath.Join(codegen.Gendir, svcName, "service.go")
21 seen := make(map[string]struct{})
22 typeDefSections := make(map[string]map[string]*codegen.SectionTemplate)
23 typesByPath := make(map[string][]string)
24 svcSections := make([]*codegen.SectionTemplate, 0, 10)
25
26 addTypeDefSection := func(path, name string, section *codegen.SectionTemplate) {
27 if typeDefSections[path] == nil {
28 typeDefSections[path] = make(map[string]*codegen.SectionTemplate)
29 }
30 typeDefSections[path][name] = section
31 typesByPath[path] = append(typesByPath[path], name)
32 seen[name] = struct{}{}
33 }
34
35 for _, m := range svc.Methods {
36 payloadPath := pathWithDefault(m.PayloadLoc, svcPath)
37 resultPath := pathWithDefault(m.ResultLoc, svcPath)
38 if m.PayloadDef != "" {
39 if _, ok := seen[m.Payload]; !ok {
40 addTypeDefSection(payloadPath, m.Payload, &codegen.SectionTemplate{
41 Name: "service-payload",
42 Source: serviceTemplates.Read(payloadT),
43 Data: m,
44 })
45 }
46 }
47 if m.StreamingPayloadDef != "" {
48 if _, ok := seen[m.StreamingPayload]; !ok {
49 addTypeDefSection(payloadPath, m.StreamingPayload, &codegen.SectionTemplate{
50 Name: "service-streaming-payload",
51 Source: serviceTemplates.Read(streamingPayloadT),
52 Data: m,
53 })
54 }
55 }
56 if m.ResultDef != "" {
57 if _, ok := seen[m.Result]; !ok {
58 addTypeDefSection(resultPath, m.Result, &codegen.SectionTemplate{
59 Name: "service-result",
60 Source: serviceTemplates.Read(resultT),
61 Data: m,
62 })
63 }
64 }
65 // Generate streaming result type if different from result
66 if m.StreamingResultDef != "" && m.StreamingResult != m.Result {
67 if _, ok := seen[m.StreamingResult]; !ok {
68 addTypeDefSection(resultPath, m.StreamingResult, &codegen.SectionTemplate{
69 Name: "service-streaming-result",
70 Source: serviceTemplates.Read(resultT),
71 Data: map[string]any{
72 "Result": m.StreamingResult,
73 "ResultDef": m.StreamingResultDef,
74 "ResultDesc": m.StreamingResultDesc,

Callers 7

ServiceFunction · 0.92
TestServiceFunction · 0.70
TestStructPkgPathFunction · 0.70
dsls.goFile · 0.50

Calls 12

AppendHelpersFunction · 0.92
SimpleImportFunction · 0.92
GoaImportFunction · 0.92
NewImportFunction · 0.92
HeaderFunction · 0.92
GoifyFunction · 0.92
pathWithDefaultFunction · 0.85
hasJSONRPCStreamingFunction · 0.85
isJSONRPCSSEFunction · 0.85
InterceptorsFilesFunction · 0.85
GetMethod · 0.45
ReadMethod · 0.45