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

Function clientFile

http/codegen/client.go:135–232  ·  view source on GitHub ↗

clientFile returns the client HTTP transport file

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

Source from the content-addressed store, hash-verified

133
134// clientFile returns the client HTTP transport file
135func clientFile(genpkg string, svc *expr.HTTPServiceExpr, services *ServicesData) *codegen.File {
136 data := services.Get(svc.Name())
137 svcName := data.Service.PathName
138 path := filepath.Join(codegen.Gendir, "http", svcName, "client", "client.go")
139 title := fmt.Sprintf("%s client HTTP transport", svc.Name())
140 sections := []*codegen.SectionTemplate{
141 codegen.Header(title, "client", []*codegen.ImportSpec{
142 {Path: "context"},
143 {Path: "fmt"},
144 {Path: "io"},
145 {Path: "mime/multipart"},
146 {Path: "net/http"},
147 {Path: "strconv"},
148 {Path: "strings"},
149 {Path: "time"},
150 {Path: "github.com/gorilla/websocket"},
151 codegen.GoaImport(""),
152 codegen.GoaNamedImport("http", "goahttp"),
153 {Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
154 {Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
155 }),
156 }
157 sections = append(sections, &codegen.SectionTemplate{
158 Name: "client-struct",
159 Source: httpTemplates.Read(clientStructT),
160 Data: data,
161 FuncMap: map[string]any{
162 "hasWebSocket": HasWebSocket,
163 "hasSSE": HasSSE,
164 },
165 })
166
167 for _, e := range data.Endpoints {
168 if e.MultipartRequestEncoder != nil {
169 sections = append(sections, &codegen.SectionTemplate{
170 Name: "multipart-request-encoder-type",
171 Source: httpTemplates.Read(multipartRequestEncoderTypeT),
172 Data: e.MultipartRequestEncoder,
173 })
174 }
175 }
176
177 sections = append(sections, &codegen.SectionTemplate{
178 Name: "http-client-init",
179 Source: httpTemplates.Read(clientInitT),
180 Data: data,
181 FuncMap: map[string]any{
182 "hasWebSocket": HasWebSocket,
183 "hasSSE": HasSSE,
184 },
185 })
186
187 for _, e := range data.Endpoints {
188 // For mixed results, generate both standard and SSE endpoints
189 if e.HasMixedResults {
190 // Generate standard HTTP endpoint
191 standardEndpoint := *e
192 standardEndpoint.SSE = nil

Callers 1

ClientFilesFunction · 0.70

Calls 6

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

Tested by

no test coverage detected