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

Method initWebSocketData

http/codegen/websocket.go:77–237  ·  view source on GitHub ↗

initWebSocketData initializes the WebSocket related data in ed.

(ed *EndpointData, e *expr.HTTPEndpointExpr, sd *ServiceData)

Source from the content-addressed store, hash-verified

75
76// initWebSocketData initializes the WebSocket related data in ed.
77func (sds *ServicesData) initWebSocketData(ed *EndpointData, e *expr.HTTPEndpointExpr, sd *ServiceData) {
78 if e.SSE != nil {
79 return
80 }
81 var (
82 svrRecvTypeName string
83 svrRecvTypeRef string
84 svrRecvDesc string
85 svrRecvWithContextDesc string
86 svrPayload *TypeData
87 cliSendDesc string
88 cliSendWithContextDesc string
89 cliPayload *TypeData
90 )
91 md := ed.Method
92 svc := sd.Service
93 svcctx := serviceContext(sd.Service.PkgName, sd.Service.Scope)
94 svrSendTypeName := ed.Result.Name
95 svrSendTypeRef := ed.Result.Ref
96 svrSendDesc := fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection.", md.ServerStream.SendName, svrSendTypeName, md.Name)
97 svrSendWithContextDesc := fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context.", md.ServerStream.SendWithContextName, svrSendTypeName, md.Name)
98 cliRecvDesc := fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection.", md.ClientStream.RecvName, svrSendTypeName, md.Name)
99 cliRecvWithContextDesc := fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection with context.", md.ClientStream.RecvWithContextName, svrSendTypeName, md.Name)
100 if e.MethodExpr.Stream == expr.ClientStreamKind || e.MethodExpr.Stream == expr.BidirectionalStreamKind {
101 svrRecvTypeName = sd.Scope.GoFullTypeName(e.MethodExpr.StreamingPayload, svc.PkgName)
102 svrRecvTypeRef = sd.Scope.GoFullTypeRef(e.MethodExpr.StreamingPayload, svc.PkgName)
103 svrPayload = sds.buildRequestBodyType(e.StreamingBody, e.MethodExpr.StreamingPayload, e, true, sd)
104 if needInit(e.MethodExpr.StreamingPayload.Type) {
105 makeHTTPType(e.StreamingBody)
106 body := e.StreamingBody.Type
107 // generate constructor function to transform request body,
108 // into the method streaming payload type
109 var (
110 name string
111 desc string
112 serverArgs []*InitArgData
113 serverCode string
114 err error
115 )
116 n := codegen.Goify(e.MethodExpr.Name, true)
117 p := codegen.Goify(svrPayload.Name, true)
118 // Raw payload object has type name prefixed with endpoint name. No need to
119 // prefix the type name again.
120 if strings.HasPrefix(p, n) {
121 name = fmt.Sprintf("New%s", p)
122 } else {
123 name = fmt.Sprintf("New%s%s", n, p)
124 }
125 desc = fmt.Sprintf("%s builds a %s service %s endpoint payload.", name, svc.Name, e.MethodExpr.Name)
126 if body != expr.Empty {
127 ref := "body"
128 if expr.IsObject(body) {
129 ref = "&body"
130 }
131 var svcode string
132 if ut, ok := body.(expr.UserType); ok {
133 if val := ut.Attribute().Validation; val != nil {
134 httpctx := httpContext(sd.Scope, true, true)

Callers 1

analyzeMethod · 0.95

Calls 15

buildRequestBodyTypeMethod · 0.95
GoifyFunction · 0.92
IsObjectFunction · 0.92
ValidationCodeFunction · 0.92
IsAliasFunction · 0.92
AppendHelpersFunction · 0.92
IsArrayFunction · 0.92
IsMapFunction · 0.92
serviceContextFunction · 0.85
needInitFunction · 0.85
makeHTTPTypeFunction · 0.85
httpContextFunction · 0.85

Tested by

no test coverage detected