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

Function serverWSSections

http/codegen/websocket.go:331–379  ·  view source on GitHub ↗

serverWSSections returns section templates that contain server WebSocket specific code for the given service.

(data *ServiceData)

Source from the content-addressed store, hash-verified

329// serverWSSections returns section templates that contain server WebSocket
330// specific code for the given service.
331func serverWSSections(data *ServiceData) []*codegen.SectionTemplate {
332 var sections []*codegen.SectionTemplate
333 sections = append(sections, &codegen.SectionTemplate{
334 Name: "server-websocket-conn-configurer-struct-init",
335 Source: httpTemplates.Read(websocketConnConfigurerStructInitT),
336 Data: data,
337 FuncMap: map[string]any{"isWebSocketEndpoint": IsWebSocketEndpoint},
338 })
339 for _, e := range data.Endpoints {
340 if e.ServerWebSocket != nil {
341 if e.ServerWebSocket.SendTypeRef != "" {
342 sections = append(sections, &codegen.SectionTemplate{
343 Name: "server-websocket-send",
344 Source: httpTemplates.Read(websocketSendT, websocketUpgradeP),
345 Data: e.ServerWebSocket,
346 FuncMap: map[string]any{
347 "upgradeParams": upgradeParams,
348 "viewedServerBody": viewedServerBody,
349 },
350 })
351 }
352 switch e.ServerWebSocket.Kind {
353 case expr.ClientStreamKind, expr.BidirectionalStreamKind:
354 sections = append(sections, &codegen.SectionTemplate{
355 Name: "server-websocket-recv",
356 Source: httpTemplates.Read(websocketRecvT, websocketUpgradeP),
357 Data: e.ServerWebSocket,
358 FuncMap: map[string]any{"upgradeParams": upgradeParams},
359 })
360 }
361 if e.ServerWebSocket.MustClose {
362 sections = append(sections, &codegen.SectionTemplate{
363 Name: "server-websocket-close",
364 Source: httpTemplates.Read(websocketCloseT),
365 Data: e.ServerWebSocket,
366 FuncMap: map[string]any{"upgradeParams": upgradeParams},
367 })
368 }
369 if e.Method.ViewedResult != nil && e.Method.ViewedResult.ViewName == "" {
370 sections = append(sections, &codegen.SectionTemplate{
371 Name: "server-websocket-set-view",
372 Source: httpTemplates.Read(websocketSetViewT),
373 Data: e.ServerWebSocket,
374 })
375 }
376 }
377 }
378 return sections
379}
380
381// clientStructWSSections return section templates that generate WebSocket
382// related struct type definitions for the client.

Callers 1

websocketServerFileFunction · 0.85

Calls 1

ReadMethod · 0.45

Tested by

no test coverage detected