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

Function endpointParser

http/codegen/client_cli.go:105–166  ·  view source on GitHub ↗

endpointParser returns the file that implements the command line parser that builds the client endpoint and payload necessary to perform a request.

(genpkg string, root *expr.RootExpr, svr *expr.ServerExpr, data []*commandData, services *ServicesData)

Source from the content-addressed store, hash-verified

103// endpointParser returns the file that implements the command line parser that
104// builds the client endpoint and payload necessary to perform a request.
105func endpointParser(genpkg string, root *expr.RootExpr, svr *expr.ServerExpr, data []*commandData, services *ServicesData) *codegen.File {
106 pkg := codegen.SnakeCase(codegen.Goify(svr.Name, true))
107 path := filepath.Join(codegen.Gendir, "http", "cli", pkg, "cli.go")
108 title := fmt.Sprintf("%s HTTP client CLI support package", svr.Name)
109 specs := []*codegen.ImportSpec{
110 {Path: "encoding/json"},
111 {Path: "flag"},
112 {Path: "fmt"},
113 {Path: "net/http"},
114 {Path: "os"},
115 {Path: "strconv"},
116 {Path: "unicode/utf8"},
117 codegen.GoaImport(""),
118 codegen.GoaNamedImport("http", "goahttp"),
119 }
120 for _, sv := range svr.Services {
121 svc := root.Service(sv)
122 sd := services.Get(svc.Name)
123 if sd == nil {
124 continue
125 }
126 specs = append(specs, &codegen.ImportSpec{
127 Path: genpkg + "/http/" + sd.Service.PathName + "/client",
128 Name: sd.Service.PkgName + "c",
129 })
130 // Add interceptors import if service has client interceptors
131 if len(sd.Service.ClientInterceptors) > 0 {
132 specs = append(specs, &codegen.ImportSpec{
133 Path: genpkg + "/" + sd.Service.PathName,
134 Name: sd.Service.PkgName,
135 })
136 }
137 }
138
139 cliData := make([]*cli.CommandData, len(data))
140 for i, cmd := range data {
141 cliData[i] = cmd.CommandData
142 }
143
144 sections := make([]*codegen.SectionTemplate, 0, 4+len(cliData))
145 sections = append(sections,
146 codegen.Header(title, "cli", specs),
147 cli.UsageCommands(cliData),
148 cli.UsageExamples(cliData),
149 &codegen.SectionTemplate{
150 Name: "parse-endpoint",
151 Source: httpTemplates.Read(parseEndpointT),
152 Data: struct {
153 FlagsCode string
154 Commands []*commandData
155 }{
156 cli.FlagsCode(cliData),
157 data,
158 },
159 FuncMap: map[string]any{"streamingCmdExists": streamingCmdExists},
160 },
161 )
162 for _, cmd := range cliData {

Callers 1

ClientCLIFilesFunction · 0.70

Calls 12

SnakeCaseFunction · 0.92
GoifyFunction · 0.92
GoaImportFunction · 0.92
GoaNamedImportFunction · 0.92
HeaderFunction · 0.92
UsageCommandsFunction · 0.92
UsageExamplesFunction · 0.92
FlagsCodeFunction · 0.92
CommandUsageFunction · 0.92
ServiceMethod · 0.65
GetMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected