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

Function sseClientFile

jsonrpc/codegen/sse.go:70–113  ·  view source on GitHub ↗

sseClientFile returns the file implementing the SSE client streaming implementation if any.

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

Source from the content-addressed store, hash-verified

68
69// sseClientFile returns the file implementing the SSE client streaming implementation if any.
70func sseClientFile(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData) *codegen.File {
71 data := services.Get(svc.Name())
72 if data == nil {
73 return nil
74 }
75
76 // Check if any endpoint has SSE
77 hasSSE := false
78 for _, ed := range data.Endpoints {
79 if ed.SSE != nil {
80 hasSSE = true
81 break
82 }
83 }
84 if !hasSSE {
85 return nil
86 }
87
88 path := filepath.Join(codegen.Gendir, "jsonrpc", codegen.SnakeCase(svc.Name()), "client", "stream.go")
89 tmplSections := sseClientStreamSections(data)
90 sections := make([]*codegen.SectionTemplate, 0, 1+len(tmplSections))
91 sections = append(sections,
92 codegen.Header(
93 "stream",
94 "client",
95 []*codegen.ImportSpec{
96 {Path: "bufio"},
97 {Path: "bytes"},
98 {Path: "context"},
99 {Path: "encoding/json"},
100 {Path: "fmt"},
101 {Path: "io"},
102 {Path: "net/http"},
103 {Path: "strings"},
104 {Path: "sync"},
105 codegen.GoaImport("jsonrpc"),
106 codegen.GoaNamedImport("http", "goahttp"),
107 {Path: genpkg + "/" + codegen.SnakeCase(svc.Name()), Name: data.Service.PkgName},
108 },
109 ),
110 )
111 sections = append(sections, tmplSections...)
112 return &codegen.File{Path: path, SectionTemplates: sections}
113}
114
115// sseServerStreamSections returns section templates for SSE server endpoints.
116func sseServerStreamSections(data *httpcodegen.ServiceData) []*codegen.SectionTemplate {

Callers 2

ClientFilesFunction · 0.70
SSEServerFilesFunction · 0.70

Calls 4

sseClientStreamSectionsFunction · 0.85
NameMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected