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

Function sseServerFile

http/codegen/sse.go:160–200  ·  view source on GitHub ↗

sseServerFile returns the file implementing the SSE server streaming implementation if any.

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

Source from the content-addressed store, hash-verified

158// sseServerFile returns the file implementing the SSE server
159// streaming implementation if any.
160func sseServerFile(genpkg string, svc *expr.HTTPServiceExpr, services *ServicesData) *codegen.File {
161 data := services.Get(svc.Name())
162 if data == nil {
163 return nil
164 }
165
166 // Check if any endpoint has SSE
167 hasSSE := false
168 for _, ed := range data.Endpoints {
169 if ed.SSE != nil {
170 hasSSE = true
171 break
172 }
173 }
174 if !hasSSE {
175 return nil
176 }
177
178 path := filepath.Join(codegen.Gendir, "http", codegen.SnakeCase(svc.Name()), "server", "sse.go")
179 tmplSections := sseTemplateSections(data)
180 sections := make([]*codegen.SectionTemplate, 0, 1+len(tmplSections))
181 sections = append(sections,
182 codegen.Header(
183 "sse",
184 "server",
185 []*codegen.ImportSpec{
186 {Path: "context"},
187 {Path: "io"},
188 {Path: "net/http"},
189 {Path: "sync"},
190 {Path: "time"},
191 {Path: "encoding/json"},
192 {Path: "fmt"},
193 {Path: genpkg + "/" + codegen.SnakeCase(svc.Name()), Name: data.Service.PkgName},
194 {Path: genpkg + "/" + codegen.SnakeCase(svc.Name()) + "/views", Name: data.Service.ViewsPkg},
195 },
196 ),
197 )
198 sections = append(sections, tmplSections...)
199 return &codegen.File{Path: path, SectionTemplates: sections}
200}
201
202// sseTemplateSections returns section templates for SSE endpoints.
203func sseTemplateSections(data *ServiceData) []*codegen.SectionTemplate {

Callers 1

ServerFilesFunction · 0.70

Calls 5

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

Tested by

no test coverage detected