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

Function websocketServerFile

jsonrpc/codegen/websocket_server.go:15–83  ·  view source on GitHub ↗

websocketServerFile returns the file implementing the JSON-RPC WebSocket server streaming implementation if any. It follows the exact same pattern as the encode/decode files: get the HTTP file and modify it for JSON-RPC.

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

Source from the content-addressed store, hash-verified

13// streaming implementation if any. It follows the exact same pattern as the encode/decode
14// files: get the HTTP file and modify it for JSON-RPC.
15func websocketServerFile(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData) *codegen.File {
16 data := services.Get(svc.Name())
17 if !httpcodegen.HasWebSocket(data) {
18 return nil
19 }
20 funcs := map[string]any{
21 "lowerInitial": lowerInitial,
22 "allErrors": allErrors,
23 "isWebSocketEndpoint": httpcodegen.IsWebSocketEndpoint,
24 }
25 svcName := data.Service.PathName
26 title := fmt.Sprintf("%s WebSocket server streaming", svc.Name())
27 imports := make([]*codegen.ImportSpec, 0, 14+len(data.Service.UserTypeImports))
28 imports = append(imports,
29 &codegen.ImportSpec{Path: "context"},
30 &codegen.ImportSpec{Path: "encoding/json"},
31 &codegen.ImportSpec{Path: "errors"},
32 &codegen.ImportSpec{Path: "fmt"},
33 &codegen.ImportSpec{Path: "io"},
34 &codegen.ImportSpec{Path: "net/http"},
35 &codegen.ImportSpec{Path: "strings"},
36 &codegen.ImportSpec{Path: "sync"},
37 &codegen.ImportSpec{Path: "time"},
38 &codegen.ImportSpec{Path: "github.com/gorilla/websocket"},
39 codegen.GoaImport(""),
40 codegen.GoaImport("jsonrpc"),
41 codegen.GoaNamedImport("http", "goahttp"),
42 &codegen.ImportSpec{Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
43 )
44 imports = append(imports, data.Service.UserTypeImports...)
45 sections := []*codegen.SectionTemplate{
46 codegen.Header(title, "server", imports),
47 {
48 Name: "jsonrpc-server-websocket-struct",
49 Source: jsonrpcTemplates.Read(websocketServerStreamT),
50 Data: data,
51 FuncMap: funcs,
52 },
53 {
54 Name: "jsonrpc-server-websocket-stream-wrapper",
55 Source: jsonrpcTemplates.Read(websocketServerStreamWrapperT),
56 Data: data,
57 FuncMap: funcs,
58 },
59 {
60 Name: "jsonrpc-server-websocket-send",
61 Source: jsonrpcTemplates.Read(websocketServerSendT),
62 Data: data,
63 FuncMap: funcs,
64 },
65 {
66 Name: "jsonrpc-server-websocket-recv",
67 Source: jsonrpcTemplates.Read(websocketServerRecvT),
68 Data: data,
69 FuncMap: funcs,
70 },
71 {
72 Name: "jsonrpc-server-websocket-close",

Callers 1

ServerFilesFunction · 0.70

Calls 4

NameMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected