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

Function clientEncodeDecode

grpc/codegen/client.go:114–167  ·  view source on GitHub ↗

clientEncodeDecode returns the file containing the gRPC client encoding and decoding logic.

(genpkg string, svc *expr.GRPCServiceExpr, services *ServicesData)

Source from the content-addressed store, hash-verified

112// clientEncodeDecode returns the file containing the gRPC client encoding and
113// decoding logic.
114func clientEncodeDecode(genpkg string, svc *expr.GRPCServiceExpr, services *ServicesData) *codegen.File {
115 var (
116 fpath string
117 sections []*codegen.SectionTemplate
118
119 data = services.Get(svc.Name())
120 )
121 {
122 svcName := data.Service.PathName
123 fpath = filepath.Join(codegen.Gendir, "grpc", svcName, "client", "encode_decode.go")
124 imports := []*codegen.ImportSpec{
125 {Path: "fmt"},
126 {Path: "context"},
127 {Path: "strconv"},
128 {Path: "unicode/utf8"},
129 {Path: "google.golang.org/grpc"},
130 {Path: "google.golang.org/grpc/metadata"},
131 codegen.GoaImport(""),
132 codegen.GoaNamedImport("grpc", "goagrpc"),
133 {Path: path.Join(genpkg, svcName), Name: data.Service.PkgName},
134 {Path: path.Join(genpkg, svcName, "views"), Name: data.Service.ViewsPkg},
135 {Path: path.Join(genpkg, "grpc", svcName, pbPkgName), Name: data.PkgName},
136 }
137 sections = []*codegen.SectionTemplate{codegen.Header(svc.Name()+" gRPC client encoders and decoders", "client", imports)}
138 fm := transTmplFuncs(svc, services)
139 fm["metadataEncodeDecodeData"] = metadataEncodeDecodeData
140 fm["typeConversionData"] = typeConversionData
141 fm["isBearer"] = isBearer
142 for _, e := range data.Endpoints {
143 sections = append(sections, &codegen.SectionTemplate{
144 Name: "remote-method-builder",
145 Source: grpcTemplates.Read(grpcRemoteMethodBuilderT),
146 Data: e,
147 })
148 if e.PayloadRef != "" {
149 sections = append(sections, &codegen.SectionTemplate{
150 Name: "request-encoder",
151 Source: grpcTemplates.Read(grpcRequestEncoderT, grpcConvertTypeToStringP, "string_conversion"),
152 Data: e,
153 FuncMap: fm,
154 })
155 }
156 if e.ResultRef != "" || e.ClientStream != nil {
157 sections = append(sections, &codegen.SectionTemplate{
158 Name: "response-decoder",
159 Source: grpcTemplates.Read(grpcResponseDecoderT, grpcConvertStringToTypeP, "type_conversion", "slice_conversion", "slice_item_conversion"),
160 Data: e,
161 FuncMap: fm,
162 })
163 }
164 }
165 }
166 return &codegen.File{Path: fpath, SectionTemplates: sections}
167}
168
169// isBearer returns true if the security scheme uses a Bearer scheme.
170func isBearer(schemes []*service.SchemeData) bool {

Callers 1

ClientFilesFunction · 0.85

Calls 7

GoaImportFunction · 0.92
GoaNamedImportFunction · 0.92
HeaderFunction · 0.92
transTmplFuncsFunction · 0.70
NameMethod · 0.65
GetMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected