buildResponseConvertData builds the convert data for the server and client responses. - server side - converts method result type to generated gRPC response type in *.pb.go - client side - converts generated gRPC response type in *.pb.go and response metadata to method result type. svr param indica
(response, result *expr.AttributeExpr, svcCtx *codegen.AttributeContext, hdrs, trlrs []*MetadataData, e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool)
| 993 | // |
| 994 | // svr param indicates that the convert data is generated for server side. |
| 995 | func (d *ServicesData) buildResponseConvertData(response, result *expr.AttributeExpr, svcCtx *codegen.AttributeContext, hdrs, trlrs []*MetadataData, e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *ConvertData { |
| 996 | if !svr && (e.MethodExpr.IsStreaming() || isEmpty(e.MethodExpr.Result.Type)) { |
| 997 | return nil |
| 998 | } |
| 999 | svc := sd.Service |
| 1000 | if svr { |
| 1001 | // server side |
| 1002 | data := d.buildInitData(result, response, "result", "message", svcCtx, true, svr, false, sd) |
| 1003 | data.Description = fmt.Sprintf("%s builds the gRPC response type from the result of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name) |
| 1004 | return &ConvertData{ |
| 1005 | SrcName: svcCtx.Scope.Name(result, svcCtx.Pkg(result), svcCtx.Pointer, svcCtx.UseDefault), |
| 1006 | SrcRef: svcCtx.Scope.Ref(result, svcCtx.Pkg(result)), |
| 1007 | TgtName: protoBufGoFullTypeName(response, sd.PkgName, sd.Scope), |
| 1008 | TgtRef: protoBufGoFullTypeRef(response, sd.PkgName, sd.Scope), |
| 1009 | Init: data, |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | // client side |
| 1014 | data := d.buildInitData(response, result, "message", "result", svcCtx, false, svr, false, sd) |
| 1015 | data.Name = fmt.Sprintf("New%sResult", codegen.Goify(e.Name(), true)) |
| 1016 | data.Description = fmt.Sprintf("%s builds the result type of the %q endpoint of the %q service from the gRPC response type.", data.Name, e.Name(), svc.Name) |
| 1017 | for _, m := range hdrs { |
| 1018 | // pass the headers as arguments to result constructor in client |
| 1019 | data.Args = append(data.Args, &InitArgData{ |
| 1020 | Name: m.VarName, |
| 1021 | Ref: m.VarName, |
| 1022 | FieldName: m.FieldName, |
| 1023 | FieldType: m.FieldType, |
| 1024 | TypeName: m.TypeName, |
| 1025 | TypeRef: m.TypeRef, |
| 1026 | Type: m.Type, |
| 1027 | Pointer: m.Pointer, |
| 1028 | Required: m.Required, |
| 1029 | Validate: m.Validate, |
| 1030 | Example: m.Example, |
| 1031 | }) |
| 1032 | } |
| 1033 | for _, m := range trlrs { |
| 1034 | // pass the trailers as arguments to result constructor in client |
| 1035 | data.Args = append(data.Args, &InitArgData{ |
| 1036 | Name: m.VarName, |
| 1037 | Ref: m.VarName, |
| 1038 | FieldName: m.FieldName, |
| 1039 | FieldType: m.FieldType, |
| 1040 | TypeName: m.TypeName, |
| 1041 | TypeRef: m.TypeRef, |
| 1042 | Type: m.Type, |
| 1043 | Pointer: m.Pointer, |
| 1044 | Required: m.Required, |
| 1045 | Validate: m.Validate, |
| 1046 | Example: m.Example, |
| 1047 | }) |
| 1048 | } |
| 1049 | return &ConvertData{ |
| 1050 | SrcName: protoBufGoFullTypeName(response, sd.PkgName, sd.Scope), |
| 1051 | SrcRef: protoBufGoFullTypeRef(response, sd.PkgName, sd.Scope), |
| 1052 | TgtName: svcCtx.Scope.Name(result, svcCtx.Pkg(result), svcCtx.Pointer, svcCtx.UseDefault), |
no test coverage detected