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

Function sseServerStreamFile

jsonrpc/codegen/sse_server.go:14–100  ·  view source on GitHub ↗

sseServerStreamFile returns the file implementing the JSON-RPC SSE server streaming implementation if any.

(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData)

Source from the content-addressed store, hash-verified

12// sseServerStreamFile returns the file implementing the JSON-RPC SSE server
13// streaming implementation if any.
14func sseServerStreamFile(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData) *codegen.File {
15 data := services.Get(svc.Name())
16 if data == nil {
17 return nil
18 }
19
20 // Check if service has streaming methods
21 hasStreaming := false
22 for _, m := range data.Service.Methods {
23 if m.ServerStream != nil {
24 hasStreaming = true
25 break
26 }
27 }
28 if !hasStreaming {
29 return nil
30 }
31
32 funcs := map[string]any{
33 "lowerInitial": lowerInitial,
34 "allErrors": allErrors,
35 "hasErrors": func() bool {
36 for _, m := range data.Service.Methods {
37 if len(m.Errors) > 0 {
38 return true
39 }
40 }
41 return false
42 },
43 "hasStreamingPayload": func() bool {
44 for _, m := range data.Service.Methods {
45 if m.StreamingPayload != "" {
46 return true
47 }
48 }
49 return false
50 },
51 // dedupeBySSEEvent returns endpoints with unique SSE event type
52 "dedupeBySSEEvent": func(eds []*httpcodegen.EndpointData) []*httpcodegen.EndpointData {
53 seen := make(map[string]struct{})
54 out := make([]*httpcodegen.EndpointData, 0, len(eds))
55 for _, e := range eds {
56 if e == nil || e.SSE == nil || e.SSE.EventTypeRef == "" {
57 continue
58 }
59 if _, ok := seen[e.SSE.EventTypeRef]; ok {
60 continue
61 }
62 seen[e.SSE.EventTypeRef] = struct{}{}
63 out = append(out, e)
64 }
65 return out
66 },
67 }
68 svcName := data.Service.PathName
69 title := fmt.Sprintf("%s SSE server streaming", svc.Name())
70 imports := make([]*codegen.ImportSpec, 0, 11+len(data.Service.UserTypeImports))
71 imports = append(imports,

Callers 1

ServerFilesFunction · 0.85

Calls 4

NameMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected