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

Function sseClientFile

http/codegen/sse_client.go:14–56  ·  view source on GitHub ↗

sseClientFile returns the file implementing the SSE client code for SSE endpoints if any. Relies on SSEData (ed.SSE) for all codegen needs.

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

Source from the content-addressed store, hash-verified

12// sseClientFile returns the file implementing the SSE client code for SSE endpoints if any.
13// Relies on SSEData (ed.SSE) for all codegen needs.
14func sseClientFile(genpkg string, svc *expr.HTTPServiceExpr, services *ServicesData) *codegen.File {
15 data := services.Get(svc.Name())
16 if data == nil {
17 return nil
18 }
19 // Check if any endpoint has SSE
20 hasSSE := false
21 for _, ed := range data.Endpoints {
22 if ed.SSE != nil {
23 hasSSE = true
24 break
25 }
26 }
27 if !hasSSE {
28 return nil
29 }
30 path := filepath.Join(codegen.Gendir, "http", codegen.SnakeCase(svc.Name()), "client", "sse.go")
31 tmplSections := sseClientTemplateSections(data)
32 sections := make([]*codegen.SectionTemplate, 0, 1+len(tmplSections))
33 sections = append(sections,
34 codegen.Header(
35 "sse-client",
36 "client",
37 []*codegen.ImportSpec{
38 {Path: "bytes"},
39 {Path: "context"},
40 {Path: "encoding/json"},
41 {Path: "errors"},
42 {Path: "io"},
43 {Path: "net/http"},
44 {Path: "fmt"},
45 {Path: "strings"},
46 {Path: "strconv"},
47 {Path: "sync"},
48 {Path: genpkg + "/" + codegen.SnakeCase(svc.Name()), Name: data.Service.PkgName},
49 {Path: genpkg + "/" + codegen.SnakeCase(svc.Name()) + "/views", Name: data.Service.ViewsPkg},
50 {Path: "goa.design/goa/v3/http", Name: "goahttp"},
51 },
52 ),
53 )
54 sections = append(sections, tmplSections...) // add SSE client methods
55 return &codegen.File{Path: path, SectionTemplates: sections}
56}
57
58// sseClientTemplateSections returns section templates for SSE client endpoints.
59func sseClientTemplateSections(data *ServiceData) []*codegen.SectionTemplate {

Callers 1

ClientFilesFunction · 0.70

Calls 5

SnakeCaseFunction · 0.92
HeaderFunction · 0.92
NameMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected