Open
Description
Go version
1.23.3
GoFrame version
2.9.0
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
Add other extension libraries such as GitHub/xuri/Excel/v2 to the already generated controller. If a new API interface is added after this, the already generated controller will be regenerated again when executing gf gen ctrl
What did you see happen?
When checking gf/cd/gf/internal/cmd/genctrl/genctrl-ast_crse.go, it was found that only the values introduced by renaming were parsed during import parsing
ast.Inspect(node, func(n ast.Node) bool {
if imp, ok := n.(*ast.ImportSpec); ok {
imports = append(imports, imp.Path.Value)
}
return true
})
What did you expect to see?
Try modifying the code to
ast.Inspect(node, func(n ast.Node) bool {
if imp, ok := n.(*ast.ImportSpec); ok {
var importStr string
if imp.Name != nil {
// 如果有别名,格式为 "别名 路径"
importStr = fmt.Sprintf("%s %s", imp.Name.Name, imp.Path.Value)
} else {
// 没有别名,直接使用路径
importStr = imp.Path.Value
}
imports = append(imports, importStr)
}
return true
})
Testing has found that executing gf gen ctrl again will not result in duplicate creation issues