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

Function ClientFile

codegen/service/client.go:16–52  ·  view source on GitHub ↗

ClientFile returns the client file for the given service.

(_ string, service *expr.ServiceExpr, services *ServicesData)

Source from the content-addressed store, hash-verified

14
15// ClientFile returns the client file for the given service.
16func ClientFile(_ string, service *expr.ServiceExpr, services *ServicesData) *codegen.File {
17 svc := services.Get(service.Name)
18 data := endpointData(svc)
19 path := filepath.Join(codegen.Gendir, svc.PathName, "client.go")
20 var (
21 sections []*codegen.SectionTemplate
22 )
23 {
24 imports := []*codegen.ImportSpec{
25 {Path: "context"},
26 {Path: "io"},
27 codegen.GoaImport(""),
28 }
29 header := codegen.Header(service.Name+" client", svc.PkgName, imports)
30 def := &codegen.SectionTemplate{
31 Name: "client-struct",
32 Source: serviceTemplates.Read(serviceClientT),
33 Data: data,
34 }
35 init := &codegen.SectionTemplate{
36 Name: "client-init",
37 Source: serviceTemplates.Read(serviceClientInitT),
38 Data: data,
39 }
40 sections = make([]*codegen.SectionTemplate, 0, 3+len(data.Methods))
41 sections = append(sections, header, def, init)
42 for _, m := range data.Methods {
43 sections = append(sections, &codegen.SectionTemplate{
44 Name: "client-method",
45 Source: serviceTemplates.Read(serviceClientMethodT),
46 Data: m,
47 })
48 }
49 }
50
51 return &codegen.File{Path: path, SectionTemplates: sections}
52}

Callers 2

ServiceFunction · 0.92
TestClientFunction · 0.85

Calls 5

GoaImportFunction · 0.92
HeaderFunction · 0.92
endpointDataFunction · 0.85
GetMethod · 0.45
ReadMethod · 0.45

Tested by 1

TestClientFunction · 0.68