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

Function payloadBuilders

grpc/codegen/client_cli.go:125–161  ·  view source on GitHub ↗

payloadBuilders returns the file that contains the payload constructors that use flag values as arguments.

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

Source from the content-addressed store, hash-verified

123// payloadBuilders returns the file that contains the payload constructors that
124// use flag values as arguments.
125func payloadBuilders(genpkg string, svc *expr.GRPCServiceExpr, data *cli.CommandData, services *ServicesData) *codegen.File {
126 sd := services.Get(svc.Name())
127 svcName := sd.Service.PathName
128 fpath := filepath.Join(codegen.Gendir, "grpc", svcName, "client", "cli.go")
129 title := svc.Name() + " gRPC client CLI support package"
130 specs := []*codegen.ImportSpec{
131 {Path: "encoding/json"},
132 {Path: "fmt"},
133 {Path: "strconv"},
134 {Path: "unicode/utf8"},
135 codegen.GoaImport(""),
136 {Path: path.Join(genpkg, svcName), Name: sd.Service.PkgName},
137 {Path: path.Join(genpkg, "grpc", svcName, pbPkgName), Name: sd.PkgName},
138 }
139 // Add structpb import if Any type is used
140 needsAnyPb := false
141 for _, e := range svc.GRPCEndpoints {
142 if hasAnyType(e.MethodExpr.Payload) || hasAnyType(e.MethodExpr.Result) {
143 needsAnyPb = true
144 break
145 }
146 }
147 if needsAnyPb {
148 specs = append(specs,
149 &codegen.ImportSpec{Path: "google.golang.org/protobuf/types/known/structpb", Name: "structpb"},
150 )
151 }
152 sections := []*codegen.SectionTemplate{
153 codegen.Header(title, "client", specs),
154 }
155 for _, sub := range data.Subcommands {
156 if sub.BuildFunction != nil {
157 sections = append(sections, cli.PayloadBuilderSection(sub.BuildFunction))
158 }
159 }
160 return &codegen.File{Path: fpath, SectionTemplates: sections}
161}
162
163func buildFlags(e *EndpointData) ([]*cli.FlagData, *cli.BuildFunctionData) {
164 if e.Request != nil {

Callers 1

ClientCLIFilesFunction · 0.70

Calls 6

GoaImportFunction · 0.92
HeaderFunction · 0.92
PayloadBuilderSectionFunction · 0.92
hasAnyTypeFunction · 0.85
NameMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected