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

Method buildResultData

http/codegen/service_data.go:1520–1583  ·  view source on GitHub ↗

buildResultData builds the result data for the given service endpoint.

(e *expr.HTTPEndpointExpr, sd *ServiceData)

Source from the content-addressed store, hash-verified

1518
1519// buildResultData builds the result data for the given service endpoint.
1520func (sds *ServicesData) buildResultData(e *expr.HTTPEndpointExpr, sd *ServiceData) *ResultData {
1521 var (
1522 svc = sd.Service
1523 ep = svc.Method(e.MethodExpr.Name)
1524 pkg = pkgWithDefault(ep.ResultLoc, svc.PkgName)
1525 result = e.MethodExpr.Result
1526
1527 name string
1528 ref string
1529 view string
1530 )
1531
1532 view = expr.DefaultView
1533 if v, ok := result.Meta.Last(expr.ViewMetaKey); ok {
1534 view = v
1535 }
1536 if result.Type != expr.Empty {
1537 name = svc.Scope.GoFullTypeName(result, pkg)
1538 ref = svc.Scope.GoFullTypeRef(result, pkg)
1539 }
1540
1541 var (
1542 mustInit bool
1543 responses []*ResponseData
1544 )
1545 {
1546 viewed := false
1547 if ep.ViewedResult != nil {
1548 result = expr.AsObject(ep.ViewedResult.Type).Attribute("projected")
1549 viewed = true
1550 }
1551 responses = sds.buildResponses(e, result, viewed, sd)
1552 for _, r := range responses {
1553 // response has a body, headers, cookies or tag
1554 if len(r.ServerBody) > 0 || len(r.Headers) > 0 || len(r.Cookies) > 0 || r.TagName != "" {
1555 mustInit = true
1556 }
1557 }
1558 }
1559 idAtt := ""
1560 idAttRequired := false
1561 if e.IsJSONRPC() && result.Type != expr.Empty {
1562 obj := expr.AsObject(result.Type)
1563 if obj != nil {
1564 for _, att := range *obj {
1565 if _, ok := att.Attribute.Meta["jsonrpc:id"]; ok {
1566 idAtt = codegen.Goify(att.Name, true)
1567 idAttRequired = result.IsRequired(att.Name)
1568 break
1569 }
1570 }
1571 }
1572 }
1573 return &ResultData{
1574 IsStruct: expr.IsObject(result.Type),
1575 Name: name,
1576 Ref: ref,
1577 IDAttribute: idAtt,

Callers 1

analyzeMethod · 0.95

Calls 12

buildResponsesMethod · 0.95
AsObjectFunction · 0.92
GoifyFunction · 0.92
IsObjectFunction · 0.92
LastMethod · 0.80
GoFullTypeNameMethod · 0.80
GoFullTypeRefMethod · 0.80
IsJSONRPCMethod · 0.80
IsRequiredMethod · 0.80
pkgWithDefaultFunction · 0.70
MethodMethod · 0.65
AttributeMethod · 0.65

Tested by

no test coverage detected