Skip to content

Commit 99cfaf1

Browse files
committed
Properly handle file servers in multiple resources
1 parent fee9bf0 commit 99cfaf1

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

goagen/gen_client/cli_generator.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ func (g *Generator) generateCommands(commandsFile string, clientPkg string, func
181181
return err
182182
}
183183

184-
err = g.API.IterateResources(func(res *design.ResourceDefinition) error {
184+
var fsdata []map[string]interface{}
185+
g.API.IterateResources(func(res *design.ResourceDefinition) error {
185186
if res.FileServers != nil {
186-
var fsdata []map[string]interface{}
187187
res.IterateFileServers(func(fs *design.FileServerDefinition) error {
188188
wcs := design.ExtractWildcards(fs.RequestPath)
189189
isDir := len(wcs) > 0
@@ -203,17 +203,22 @@ func (g *Generator) generateCommands(commandsFile string, clientPkg string, func
203203
})
204204
return nil
205205
})
206-
data := struct {
207-
Package string
208-
FileServers []map[string]interface{}
209-
}{
210-
Package: g.Target,
211-
FileServers: fsdata,
212-
}
213-
if err := downloadCommandTmpl.Execute(file, data); err != nil {
214-
return err
215-
}
216206
}
207+
return nil
208+
})
209+
if fsdata != nil {
210+
data := struct {
211+
Package string
212+
FileServers []map[string]interface{}
213+
}{
214+
Package: g.Target,
215+
FileServers: fsdata,
216+
}
217+
if err := downloadCommandTmpl.Execute(file, data); err != nil {
218+
return err
219+
}
220+
}
221+
err = g.API.IterateResources(func(res *design.ResourceDefinition) error {
217222
return res.IterateActions(func(action *design.ActionDefinition) error {
218223
data := map[string]interface{}{
219224
"Action": action,

0 commit comments

Comments
 (0)