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

Function computeHandlerArgsForURI

codegen/example/server_data.go:387–485  ·  view source on GitHub ↗

computeHandlerArgsForURI returns the ordered handler arguments for the given URI. For HTTP URIs that serve both HTTP and JSON-RPC services, the order is: - HTTP service endpoints (for services in the HTTP transport list) - JSON-RPC service interfaces (in JSONRPC.Services order) - JSON-RPC service en

(uri *URIData, server *Data, root *expr.RootExpr)

Source from the content-addressed store, hash-verified

385// - JSON-RPC service interfaces (in JSONRPC.Services order)
386// - JSON-RPC service endpoints (for services not already added as HTTP endpoints)
387func computeHandlerArgsForURI(uri *URIData, server *Data, root *expr.RootExpr) []HandlerArg {
388 capHint := len(server.Services)
389 grpcSvcNames := make([]string, 0, capHint)
390 for _, t := range server.Transports {
391 if t.Type == TransportGRPC {
392 grpcSvcNames = append(grpcSvcNames, t.Services...)
393 }
394 }
395 if uri.Transport.Type == TransportGRPC {
396 out := make([]HandlerArg, 0, len(grpcSvcNames))
397 for _, name := range grpcSvcNames {
398 out = append(out, HandlerArg{Endpoint: codegen.Goify(name, false) + "Endpoints"})
399 }
400 return out
401 }
402
403 var jsonrpcServices []*expr.HTTPServiceExpr
404 if root.API != nil && root.API.JSONRPC != nil {
405 jsonrpcServices = root.API.JSONRPC.Services
406 }
407
408 httpSvcSet := make(map[string]struct{}, len(server.Services))
409 for _, t := range server.Transports {
410 if t.Type != TransportHTTP {
411 continue
412 }
413 for _, name := range t.Services {
414 httpSvcSet[name] = struct{}{}
415 }
416 }
417
418 out := make([]HandlerArg, 0, len(server.Services)+len(jsonrpcServices))
419
420 serviceHasHandlers := func(name string) bool {
421 if svc := root.Service(name); len(svc.Methods) > 0 {
422 return true
423 }
424 if hs := root.API.HTTP.Service(name); hs != nil && len(hs.HTTPEndpoints) > 0 {
425 return true
426 }
427 if js := root.API.JSONRPC.Service(name); js != nil && len(js.HTTPEndpoints) > 0 {
428 return true
429 }
430 return false
431 }
432
433 // Build set of services that are in $.Services for the template.
434 // The template data depends on whether there are HTTP services:
435 // - If there are HTTP services: $.Services = HTTP services only
436 // - If there are NO HTTP services: $.Services = all JSON-RPC services
437 servicesInTemplate := make(map[string]struct{})
438 hasHTTPServices := false
439 if root.API != nil && root.API.HTTP != nil && len(root.API.HTTP.Services) > 0 {
440 hasHTTPServices = true
441 for _, hs := range root.API.HTTP.Services {
442 if hs.ServiceExpr != nil {
443 servicesInTemplate[hs.ServiceExpr.Name] = struct{}{}
444 }

Callers 2

buildServerDataFunction · 0.85

Calls 2

GoifyFunction · 0.92
ServiceMethod · 0.65