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

Function clientFile

jsonrpc/codegen/client.go:79–148  ·  view source on GitHub ↗

clientFile returns the client HTTP transport file

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

Source from the content-addressed store, hash-verified

77
78// clientFile returns the client HTTP transport file
79func clientFile(genpkg string, svc *expr.HTTPServiceExpr, services *httpcodegen.ServicesData) *codegen.File {
80 data := services.Get(svc.Name())
81 svcName := data.Service.PathName
82 path := filepath.Join(codegen.Gendir, "jsonrpc", svcName, "client", "client.go")
83 title := fmt.Sprintf("%s client JSON-RPC transport", svc.Name())
84 sections := []*codegen.SectionTemplate{
85 codegen.Header(title, "client", []*codegen.ImportSpec{
86 {Path: "bufio"},
87 {Path: "bytes"},
88 {Path: "context"},
89 {Path: "fmt"},
90 {Path: "io"},
91 {Path: "net/http"},
92 {Path: "strconv"},
93 {Path: "strings"},
94 {Path: "sync"},
95 {Path: "sync/atomic"},
96 {Path: "time"},
97 {Path: "github.com/gorilla/websocket"},
98 codegen.GoaImport(""),
99 codegen.GoaImport("jsonrpc"),
100 codegen.GoaNamedImport("http", "goahttp"),
101 {Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
102 {Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
103 }),
104 }
105 sections = append(sections, &codegen.SectionTemplate{
106 Name: "jsonrpc-client-struct",
107 Source: jsonrpcTemplates.Read(clientStructT),
108 Data: data,
109 FuncMap: map[string]any{
110 "hasWebSocket": httpcodegen.HasWebSocket,
111 "hasSSE": httpcodegen.HasSSE,
112 "isSSEEndpoint": httpcodegen.IsSSEEndpoint,
113 },
114 })
115
116 sections = append(sections, &codegen.SectionTemplate{
117 Name: "jsonrpc-client-init",
118 Source: jsonrpcTemplates.Read(clientInitT),
119 Data: data,
120 FuncMap: map[string]any{
121 "hasWebSocket": httpcodegen.HasWebSocket,
122 "hasSSE": httpcodegen.HasSSE,
123 "isSSEEndpoint": httpcodegen.IsSSEEndpoint,
124 },
125 })
126
127 for _, e := range data.Endpoints {
128 sections = append(sections, &codegen.SectionTemplate{
129 Name: "jsonrpc-client-endpoint-init",
130 Source: jsonrpcTemplates.Read(clientEndpointInitT),
131 Data: e,
132 FuncMap: map[string]any{
133 "isWebSocketEndpoint": httpcodegen.IsWebSocketEndpoint,
134 "isSSEEndpoint": httpcodegen.IsSSEEndpoint,
135 },
136 })

Callers 1

ClientFilesFunction · 0.70

Calls 4

NameMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected