payloadBuilders returns the file that contains the payload constructors that use flag values as arguments.
(genpkg string, svc *expr.HTTPServiceExpr, data *cli.CommandData, services *ServicesData)
| 168 | // payloadBuilders returns the file that contains the payload constructors that |
| 169 | // use flag values as arguments. |
| 170 | func payloadBuilders(genpkg string, svc *expr.HTTPServiceExpr, data *cli.CommandData, services *ServicesData) *codegen.File { |
| 171 | sd := services.Get(svc.Name()) |
| 172 | path := filepath.Join(codegen.Gendir, "http", sd.Service.PathName, "client", "cli.go") |
| 173 | title := fmt.Sprintf("%s HTTP client CLI support package", svc.Name()) |
| 174 | specs := []*codegen.ImportSpec{ |
| 175 | {Path: "encoding/json"}, |
| 176 | {Path: "fmt"}, |
| 177 | {Path: "net/http"}, |
| 178 | {Path: "os"}, |
| 179 | {Path: "strconv"}, |
| 180 | {Path: "unicode/utf8"}, |
| 181 | codegen.GoaImport(""), |
| 182 | codegen.GoaNamedImport("http", "goahttp"), |
| 183 | {Path: genpkg + "/" + sd.Service.PathName, Name: sd.Service.PkgName}, |
| 184 | } |
| 185 | sections := []*codegen.SectionTemplate{ |
| 186 | codegen.Header(title, "client", specs), |
| 187 | } |
| 188 | for _, sub := range data.Subcommands { |
| 189 | if sub.BuildFunction != nil { |
| 190 | sections = append(sections, cli.PayloadBuilderSection(sub.BuildFunction)) |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return &codegen.File{Path: path, SectionTemplates: sections} |
| 195 | } |
| 196 | |
| 197 | // buildFlags builds the flag data and build function for an endpoint. |
| 198 | func buildFlags(svc *ServiceData, e *EndpointData) ([]*cli.FlagData, *cli.BuildFunctionData) { |
no test coverage detected