clientWSSections returns section templates that contain client WebSocket specific code for the given service.
(data *ServiceData)
| 403 | // clientWSSections returns section templates that contain client WebSocket |
| 404 | // specific code for the given service. |
| 405 | func clientWSSections(data *ServiceData) []*codegen.SectionTemplate { |
| 406 | var sections []*codegen.SectionTemplate |
| 407 | sections = append(sections, &codegen.SectionTemplate{ |
| 408 | Name: "client-websocket-conn-configurer-struct-init", |
| 409 | Source: httpTemplates.Read(websocketConnConfigurerStructInitT), |
| 410 | Data: data, |
| 411 | FuncMap: map[string]any{"isWebSocketEndpoint": IsWebSocketEndpoint}, |
| 412 | }) |
| 413 | for _, e := range data.Endpoints { |
| 414 | if e.ClientWebSocket != nil { |
| 415 | if e.ClientWebSocket.RecvTypeRef != "" { |
| 416 | sections = append(sections, &codegen.SectionTemplate{ |
| 417 | Name: "client-websocket-recv", |
| 418 | Source: httpTemplates.Read(websocketRecvT, websocketUpgradeP), |
| 419 | Data: e.ClientWebSocket, |
| 420 | FuncMap: map[string]any{"upgradeParams": upgradeParams}, |
| 421 | }) |
| 422 | } |
| 423 | switch e.ClientWebSocket.Kind { |
| 424 | case expr.ClientStreamKind, expr.BidirectionalStreamKind: |
| 425 | sections = append(sections, &codegen.SectionTemplate{ |
| 426 | Name: "client-websocket-send", |
| 427 | Source: httpTemplates.Read(websocketSendT, websocketUpgradeP), |
| 428 | Data: e.ClientWebSocket, |
| 429 | FuncMap: map[string]any{ |
| 430 | "upgradeParams": upgradeParams, |
| 431 | "viewedServerBody": viewedServerBody, |
| 432 | }, |
| 433 | }) |
| 434 | } |
| 435 | if e.ClientWebSocket.MustClose { |
| 436 | sections = append(sections, &codegen.SectionTemplate{ |
| 437 | Name: "client-websocket-close", |
| 438 | Source: httpTemplates.Read(websocketCloseT), |
| 439 | Data: e.ClientWebSocket, |
| 440 | FuncMap: map[string]any{"upgradeParams": upgradeParams}, |
| 441 | }) |
| 442 | } |
| 443 | if e.Method.ViewedResult != nil && e.Method.ViewedResult.ViewName == "" { |
| 444 | sections = append(sections, &codegen.SectionTemplate{ |
| 445 | Name: "client-websocket-set-view", |
| 446 | Source: httpTemplates.Read(websocketSetViewT), |
| 447 | Data: e.ClientWebSocket, |
| 448 | }) |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | return sections |
| 453 | } |
| 454 | |
| 455 | // HasWebSocket returns true if at least one of the endpoints in the service |
| 456 | // defines a streaming payload or result. |
no test coverage detected