complete route generator
This commit is contained in:
@@ -27,6 +27,8 @@ func buildRenderData(opts RenderBuildOpts) (RenderData, error) {
|
|||||||
|
|
||||||
imports := []string{}
|
imports := []string{}
|
||||||
controllers := []string{}
|
controllers := []string{}
|
||||||
|
// Track if any param uses model lookup, which requires the field package.
|
||||||
|
needsFieldImport := false
|
||||||
|
|
||||||
for _, route := range opts.Routes {
|
for _, route := range opts.Routes {
|
||||||
imports = append(imports, route.Imports...)
|
imports = append(imports, route.Imports...)
|
||||||
@@ -43,6 +45,9 @@ func buildRenderData(opts RenderBuildOpts) (RenderData, error) {
|
|||||||
if tok == "" {
|
if tok == "" {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
if item.Model != "" {
|
||||||
|
needsFieldImport = true
|
||||||
|
}
|
||||||
return tok, true
|
return tok, true
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -57,6 +62,11 @@ func buildRenderData(opts RenderBuildOpts) (RenderData, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add field import if any model lookups are used
|
||||||
|
if needsFieldImport {
|
||||||
|
imports = append(imports, `field "go.ipao.vip/gen/field"`)
|
||||||
|
}
|
||||||
|
|
||||||
// de-dup and sort imports/controllers for stable output
|
// de-dup and sort imports/controllers for stable output
|
||||||
rd.Imports = lo.Uniq(imports)
|
rd.Imports = lo.Uniq(imports)
|
||||||
sort.Strings(rd.Imports)
|
sort.Strings(rd.Imports)
|
||||||
|
|||||||
Reference in New Issue
Block a user