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

Function dummyMultipartFile

http/codegen/example_server.go:135–195  ·  view source on GitHub ↗

dummyMultipartFile returns a dummy implementation of the multipart decoders and encoders.

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

Source from the content-addressed store, hash-verified

133// dummyMultipartFile returns a dummy implementation of the multipart decoders
134// and encoders.
135func dummyMultipartFile(genpkg string, root *expr.RootExpr, svc *expr.HTTPServiceExpr, services *ServicesData) *codegen.File {
136 mpath := "multipart.go"
137 if _, err := os.Stat(mpath); !os.IsNotExist(err) {
138 return nil // file already exists, skip it.
139 }
140 var (
141 sections []*codegen.SectionTemplate
142 mustGen bool
143
144 scope = codegen.NewNameScope()
145 )
146 // determine the unique API package name different from the service names
147 for _, httpSvc := range root.API.HTTP.Services {
148 s := services.Get(httpSvc.Name())
149 if s == nil {
150 panic("unknown http service, " + httpSvc.Name()) // bug
151 }
152 if s.Service == nil {
153 panic("unknown service, " + httpSvc.Name()) // bug
154 }
155 scope.Unique(s.Service.PkgName)
156 }
157 {
158 specs := make([]*codegen.ImportSpec, 0, 2)
159 specs = append(specs, &codegen.ImportSpec{Path: "mime/multipart"})
160 data := services.Get(svc.Name())
161 specs = append(specs, &codegen.ImportSpec{
162 Path: path.Join(genpkg, data.Service.PathName),
163 Name: scope.Unique(data.Service.PkgName, "svc"),
164 })
165
166 apiPkg := scope.Unique(strings.ToLower(codegen.Goify(root.API.Name, false)), "api")
167 sections = []*codegen.SectionTemplate{codegen.Header("", apiPkg, specs)}
168 for _, e := range data.Endpoints {
169 if e.MultipartRequestDecoder != nil {
170 mustGen = true
171 sections = append(sections, &codegen.SectionTemplate{
172 Name: "dummy-multipart-request-decoder",
173 Source: httpTemplates.Read(dummyMultipartRequestDecoderT),
174 Data: e.MultipartRequestDecoder,
175 })
176 }
177 if e.MultipartRequestEncoder != nil {
178 mustGen = true
179 sections = append(sections, &codegen.SectionTemplate{
180 Name: "dummy-multipart-request-encoder",
181 Source: httpTemplates.Read(dummyMultipartRequestEncoderT),
182 Data: e.MultipartRequestEncoder,
183 })
184 }
185 }
186 }
187 if !mustGen {
188 return nil
189 }
190 return &codegen.File{
191 Path: mpath,
192 SectionTemplates: sections,

Callers 1

ExampleServerFilesFunction · 0.85

Calls 7

NewNameScopeFunction · 0.92
GoifyFunction · 0.92
HeaderFunction · 0.92
UniqueMethod · 0.80
NameMethod · 0.65
GetMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected