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

Function JSONRPC

dsl/jsonrpc.go:208–241  ·  view source on GitHub ↗

JSONRPC configures a service to use JSON-RPC 2.0 transport. The generated code handles JSON-RPC protocol details: request parsing, method dispatch, response formatting, and batch processing. All service JSON-RPC methods share a single HTTP endpoint and must use the same transport (HTTP, WebSocket or

(dsl func())

Source from the content-addressed store, hash-verified

206// })
207// })
208func JSONRPC(dsl func()) {
209 switch actual := eval.Current().(type) {
210 case *expr.APIExpr:
211 eval.Execute(dsl, actual.JSONRPC)
212 case *expr.ServiceExpr:
213 svc := expr.Root.API.JSONRPC.ServiceFor(actual, &expr.Root.API.JSONRPC.HTTPExpr)
214 svc.DSLFunc = dsl
215 // Mark service as JSON-RPC
216 if actual.Meta == nil {
217 actual.Meta = expr.MetaExpr{}
218 }
219 actual.Meta["jsonrpc:service"] = []string{}
220 case *expr.MethodExpr:
221 // Auto-enable JSON-RPC on service if not already enabled
222 if actual.Service.Meta == nil {
223 actual.Service.Meta = expr.MetaExpr{}
224 }
225 actual.Service.Meta["jsonrpc:service"] = []string{}
226
227 svc := expr.Root.API.JSONRPC.ServiceFor(actual.Service, &expr.Root.API.JSONRPC.HTTPExpr)
228 e := svc.EndpointFor(actual)
229 if e.Meta == nil {
230 e.Meta = expr.MetaExpr{}
231 }
232 e.Meta["jsonrpc"] = []string{}
233 if actual.Meta == nil {
234 actual.Meta = expr.MetaExpr{}
235 }
236 actual.Meta["jsonrpc"] = []string{}
237 e.DSLFunc = dsl
238 default:
239 eval.IncompatibleDSL()
240 }
241}
242
243// ID defines the payload or result attribute which is used as the JSON-RPC
244// request ID. It must be of type String. It is an error to omit ID on a

Calls 5

CurrentFunction · 0.92
ExecuteFunction · 0.92
IncompatibleDSLFunction · 0.92
ServiceForMethod · 0.45
EndpointForMethod · 0.45

Tested by 1