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

Method buildRequestConvertData

grpc/codegen/service_data.go:930–985  ·  view source on GitHub ↗

buildRequestConvertData builds the convert data for the server and client requests. - server side - converts the one-shot gRPC request message (if any) and gRPC metadata to the method payload type. - client side - converts the method payload type to the one-shot gRPC request message sent before any

(request, payload *expr.AttributeExpr, md []*MetadataData, e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool)

Source from the content-addressed store, hash-verified

928//
929// svr param indicates that the convert data is generated for server side.
930func (d *ServicesData) buildRequestConvertData(request, payload *expr.AttributeExpr, md []*MetadataData, e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *ConvertData {
931 if svr && isEmpty(payload.Type) {
932 return nil
933 }
934 if !svr && e.MethodExpr.IsPayloadStreaming() && isEmpty(request.Type) {
935 return nil
936 }
937 if svr && e.MethodExpr.IsPayloadStreaming() && isEmpty(request.Type) && !expr.IsObject(payload.Type) {
938 return nil
939 }
940
941 svc := sd.Service
942 pkg := pkgWithDefault(svc.Method(e.MethodExpr.Name).PayloadLoc, svc.PkgName)
943 svcCtx := serviceTypeContext(pkg, svc.Scope)
944 if svr {
945 // server side
946 data := d.buildInitData(request, payload, "message", "v", svcCtx, false, svr, false, sd)
947 data.Name = fmt.Sprintf("New%sPayload", codegen.Goify(e.Name(), true))
948 data.Description = fmt.Sprintf("%s builds the payload of the %q endpoint of the %q service from the gRPC request type.", data.Name, e.Name(), svc.Name)
949 for _, m := range md {
950 // pass the metadata as arguments to payload constructor in server
951 data.Args = append(data.Args, &InitArgData{
952 Name: m.VarName,
953 Ref: m.VarName,
954 FieldName: m.FieldName,
955 FieldType: m.FieldType,
956 TypeName: m.TypeName,
957 TypeRef: m.TypeRef,
958 Type: m.Type,
959 Pointer: m.Pointer,
960 Required: m.Required,
961 Validate: m.Validate,
962 Example: m.Example,
963 })
964 }
965 return &ConvertData{
966 SrcName: protoBufGoFullTypeName(request, sd.PkgName, sd.Scope),
967 SrcRef: protoBufGoFullTypeRef(request, sd.PkgName, sd.Scope),
968 TgtName: svc.Scope.GoFullTypeName(payload, svcCtx.Pkg(payload)),
969 TgtRef: svc.Scope.GoFullTypeRef(payload, svcCtx.Pkg(payload)),
970 Init: data,
971 Validation: addValidation(request, "message", sd, true),
972 }
973 }
974
975 // client side
976 data := d.buildInitData(payload, request, "payload", "message", svcCtx, true, svr, false, sd)
977 data.Description = fmt.Sprintf("%s builds the gRPC request type from the payload of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name)
978 return &ConvertData{
979 SrcName: svc.Scope.GoFullTypeName(payload, pkg),
980 SrcRef: svc.Scope.GoFullTypeRef(payload, pkg),
981 TgtName: protoBufGoFullTypeName(request, sd.PkgName, sd.Scope),
982 TgtRef: protoBufGoFullTypeRef(request, sd.PkgName, sd.Scope),
983 Init: data,
984 }
985}
986
987// buildResponseConvertData builds the convert data for the server and client

Callers 1

analyzeMethod · 0.95

Calls 15

buildInitDataMethod · 0.95
IsObjectFunction · 0.92
GoifyFunction · 0.92
serviceTypeContextFunction · 0.85
protoBufGoFullTypeNameFunction · 0.85
protoBufGoFullTypeRefFunction · 0.85
addValidationFunction · 0.85
IsPayloadStreamingMethod · 0.80
GoFullTypeNameMethod · 0.80
PkgMethod · 0.80
GoFullTypeRefMethod · 0.80
isEmptyFunction · 0.70

Tested by

no test coverage detected