8000 os/gtime: gf gen ctrl repeat creation controller · Issue #4289 · gogf/gf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
os/gtime: gf gen ctrl repeat creation controller #4289
Open
@black1552

Description

@black1552

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIt is confirmed a bug, but don't worry, we'll handle it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0