sseServerFile returns the file implementing the SSE server streaming implementation if any.
(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData)
| 25 | |
| 26 | // sseServerFile returns the file implementing the SSE server streaming implementation if any. |
| 27 | func sseServerFile(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData) *codegen.File { |
| 28 | data := services.Get(svc.Name()) |
| 29 | if data == nil { |
| 30 | return nil |
| 31 | } |
| 32 | |
| 33 | // Check if any endpoint has SSE |
| 34 | hasSSE := false |
| 35 | for _, ed := range data.Endpoints { |
| 36 | if ed.SSE != nil { |
| 37 | hasSSE = true |
| 38 | break |
| 39 | } |
| 40 | } |
| 41 | if !hasSSE { |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | path := filepath.Join(codegen.Gendir, "jsonrpc", codegen.SnakeCase(svc.Name()), "server", "stream.go") |
| 46 | tmplSections := sseServerStreamSections(data) |
| 47 | sections := make([]*codegen.SectionTemplate, 0, 1+len(tmplSections)) |
| 48 | sections = append(sections, |
| 49 | codegen.Header( |
| 50 | "stream", |
| 51 | "server", |
| 52 | []*codegen.ImportSpec{ |
| 53 | {Path: "context"}, |
| 54 | {Path: "errors"}, |
| 55 | {Path: "fmt"}, |
| 56 | {Path: "net/http"}, |
| 57 | {Path: "sync"}, |
| 58 | codegen.GoaImport(""), |
| 59 | codegen.GoaImport("jsonrpc"), |
| 60 | codegen.GoaNamedImport("http", "goahttp"), |
| 61 | {Path: genpkg + "/" + codegen.SnakeCase(svc.Name()), Name: data.Service.PkgName}, |
| 62 | }, |
| 63 | ), |
| 64 | ) |
| 65 | sections = append(sections, tmplSections...) |
| 66 | return &codegen.File{Path: path, SectionTemplates: sections} |
| 67 | } |
| 68 | |
| 69 | // sseClientFile returns the file implementing the SSE client streaming implementation if any. |
| 70 | func sseClientFile(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData) *codegen.File { |
no test coverage detected