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)
| 123 | // payloadBuilders returns the file that contains the payload constructors that |
| 124 | // use flag values as arguments. |
| 125 | func 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 | |
| 163 | func buildFlags(e *EndpointData) ([]*cli.FlagData, *cli.BuildFunctionData) { |
| 164 | if e.Request != nil { |
no test coverage detected