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

Function EndpointFile

codegen/service/endpoint.go:71–146  ·  view source on GitHub ↗

EndpointFile returns the endpoint file for the given service.

(genpkg string, service *expr.ServiceExpr, services *ServicesData)

Source from the content-addressed store, hash-verified

69
70// EndpointFile returns the endpoint file for the given service.
71func EndpointFile(genpkg string, service *expr.ServiceExpr, services *ServicesData) *codegen.File {
72 svc := services.Get(service.Name)
73 svcName := svc.PathName
74 path := filepath.Join(codegen.Gendir, svcName, "endpoints.go")
75 data := endpointData(svc)
76 var (
77 sections []*codegen.SectionTemplate
78 )
79 {
80 imports := []*codegen.ImportSpec{
81 {Path: "context"},
82 {Path: "io"},
83 {Path: "fmt"},
84 codegen.GoaImport(""),
85 codegen.GoaImport("security"),
86 {Path: genpkg + "/" + svcName + "/" + "views", Name: svc.ViewsPkg},
87 }
88 header := codegen.Header(service.Name+" endpoints", svc.PkgName, imports)
89 def := &codegen.SectionTemplate{
90 Name: "endpoints-struct",
91 Source: serviceTemplates.Read(serviceEndpointsT),
92 Data: data,
93 }
94 sections = []*codegen.SectionTemplate{header, def}
95 for _, m := range data.Methods {
96 if m.ServerStream != nil {
97 // Generate endpoint input struct for streaming methods
98 // For JSON-RPC WebSocket with StreamingResult: generate struct (needed for stream handle)
99 // For JSON-RPC WebSocket without StreamingResult (client streaming only): no struct needed
100 // For JSON-RPC SSE: always generate struct (methods have stream params)
101 // For HTTP/gRPC: always generate endpoint input struct
102 isJSONRPCWebSocket := m.IsJSONRPC && !isJSONRPCSSE(services, service)
103 if !isJSONRPCWebSocket || (isJSONRPCWebSocket && m.ServerStream.EndpointStruct != "") {
104 sections = append(sections, &codegen.SectionTemplate{
105 Name: "endpoint-input-struct",
106 Source: serviceTemplates.Read(serviceEndpointStreamStructT),
107 Data: m,
108 })
109 }
110 }
111 if m.SkipRequestBodyEncodeDecode {
112 sections = append(sections, &codegen.SectionTemplate{
113 Name: "request-body-struct",
114 Source: serviceTemplates.Read(serviceRequestBodyStructT),
115 Data: m,
116 })
117 }
118 if m.SkipResponseBodyEncodeDecode {
119 sections = append(sections, &codegen.SectionTemplate{
120 Name: "response-body-struct",
121 Source: serviceTemplates.Read(serviceResponseBodyStructT),
122 Data: m,
123 })
124 }
125 }
126 sections = append(sections, &codegen.SectionTemplate{
127 Name: "endpoints-init",
128 Source: serviceTemplates.Read(serviceEndpointsInitT),

Callers 5

ServiceFunction · 0.92
TestSecureEndpointInitFunction · 0.85
TestSecureEndpointFunction · 0.85
TestEndpointFunction · 0.85

Calls 6

GoaImportFunction · 0.92
HeaderFunction · 0.92
endpointDataFunction · 0.85
isJSONRPCSSEFunction · 0.85
GetMethod · 0.45
ReadMethod · 0.45

Tested by 4

TestSecureEndpointInitFunction · 0.68
TestSecureEndpointFunction · 0.68
TestEndpointFunction · 0.68