sseClientFile returns the file implementing the SSE client streaming implementation if any.
(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData)
| 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 { |
| 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. |
| 116 | func sseServerStreamSections(data *httpcodegen.ServiceData) []*codegen.SectionTemplate { |
no test coverage detected