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

Function ServerEncodeDecodeFile

http/codegen/server.go:121–197  ·  view source on GitHub ↗

ServerEncodeDecodeFile returns the file defining the HTTP server encoding and decoding logic.

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

Source from the content-addressed store, hash-verified

119// ServerEncodeDecodeFile returns the file defining the HTTP server encoding and
120// decoding logic.
121func ServerEncodeDecodeFile(genpkg string, svc *expr.HTTPServiceExpr, services *ServicesData) *codegen.File {
122 data := services.Get(svc.Name())
123 svcName := data.Service.PathName
124 path := filepath.Join(codegen.Gendir, "http", svcName, "server", "encode_decode.go")
125 title := fmt.Sprintf("%s HTTP server encoders and decoders", svc.Name())
126 imports := []*codegen.ImportSpec{
127 {Path: "context"},
128 {Path: "errors"},
129 {Path: "fmt"},
130 {Path: "io"},
131 {Path: "net/http"},
132 {Path: "strconv"},
133 {Path: "strings"},
134 {Path: "encoding/json"},
135 {Path: "mime/multipart"},
136 {Path: "unicode/utf8"},
137 codegen.GoaImport(""),
138 codegen.GoaNamedImport("http", "goahttp"),
139 {Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
140 {Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
141 }
142 sections := []*codegen.SectionTemplate{codegen.Header(title, "server", imports)}
143
144 for _, e := range data.Endpoints {
145 if e.Redirect == nil && (!IsWebSocketEndpoint(e) || e.Method.IsJSONRPC) {
146 sections = append(sections, &codegen.SectionTemplate{
147 Name: "response-encoder",
148 FuncMap: transTmplFuncs(svc, services),
149 Source: httpTemplates.Read(responseEncoderT, responseP, headerConversionP),
150 Data: e,
151 })
152 }
153 if mustDecodeRequest(e) {
154 fm := transTmplFuncs(svc, services)
155 fm["mapQueryDecodeData"] = mapQueryDecodeData
156 sections = append(sections, &codegen.SectionTemplate{
157 Name: "request-decoder",
158 Source: httpTemplates.Read(requestDecoderT, requestElementsP, sliceItemConversionP, elementSliceConversionP, querySliceConversionP, queryTypeConversionP, queryMapConversionP, pathConversionP),
159 FuncMap: fm,
160 Data: e,
161 })
162 }
163 if e.MultipartRequestDecoder != nil {
164 fm := transTmplFuncs(svc, services)
165 fm["mapQueryDecodeData"] = mapQueryDecodeData
166 sections = append(sections, &codegen.SectionTemplate{
167 Name: "multipart-request-decoder",
168 Source: httpTemplates.Read(multipartRequestDecoderT, requestElementsP, sliceItemConversionP, elementSliceConversionP, querySliceConversionP, queryTypeConversionP, queryMapConversionP, pathConversionP),
169 FuncMap: fm,
170 Data: e.MultipartRequestDecoder,
171 })
172 }
173 if len(e.Errors) > 0 {
174 sections = append(sections, &codegen.SectionTemplate{
175 Name: "error-encoder",
176 Source: httpTemplates.Read(errorEncoderT, responseP, headerConversionP),
177 FuncMap: transTmplFuncs(svc, services),
178 Data: e,

Callers 2

ServerFilesFunction · 0.85

Calls 9

GoaImportFunction · 0.92
GoaNamedImportFunction · 0.92
HeaderFunction · 0.92
IsWebSocketEndpointFunction · 0.85
mustDecodeRequestFunction · 0.85
transTmplFuncsFunction · 0.70
NameMethod · 0.65
GetMethod · 0.45
ReadMethod · 0.45

Tested by 1