Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gf gen service import the wrong version of the package #2971

Open
wheelergeo opened this issue Sep 18, 2023 · 6 comments
Open

gf gen service import the wrong version of the package #2971

wheelergeo opened this issue Sep 18, 2023 · 6 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. CLI about gf cli enhancement help wanted planned This issue/proposal is planned into our next steps.

Comments

@wheelergeo
Copy link

1. What version of Go and system type/arch are you using?

go version go1.20.3 linux/amd64

2. What version of GoFrame are you using?

GoFrame CLI Tool v2.5.4

3. Can this issue be re-produced with the latest release?

yes

4. What did you do?

1. logic file `import "github.com/gogf/gf/v2/os/gtime"`
2. use `gf gen service -s internal/app/common/logic -d internal/app/common/service/`
3. service import wrong version of the package `import "github.com/gogf/gf/os/gtime"`

5. What did you expect to see?

generated service file `import "github.com/gogf/gf/v2/os/gtime"`

6. What did you see instead?

generated service file import "github.com/gogf/gf/os/gtime"

@gqcn
Copy link
Member

gqcn commented Sep 18, 2023

@wheelergeo It seems that there's some improvement for this function. It should check line by line for the imports part of go file content, not for all content of go file.
image
image

@gqcn gqcn added enhancement help wanted planned This issue/proposal is planned into our next steps. bug It is confirmed a bug, but don't worry, we'll handle it. labels Sep 18, 2023
@github-actions
Copy link

Hello @wheelergeo. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @wheelergeo。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

@yzy613
Copy link

yzy613 commented Oct 16, 2023

I have another question. gf gen service imported the wrong package. goframe version is 2.5.4
image
image
As for why the import error occurs, I think it may be because the two api packages have the same method.
Then when two packages should be imported, only one package is imported.

@yzy613
Copy link

yzy613 commented Oct 18, 2023

When I import multiple api v1 packages in the logic package, there is a chance that there will be an import error when it is automatically generated and the compilation will fail.

@hailaz hailaz added the CLI about gf cli label Nov 1, 2023
@yzy613
Copy link

yzy613 commented Dec 7, 2023

I have another question. gf gen service imported the wrong package. goframe version is 2.5.4 image image As for why the import error occurs, I think it may be because the two api packages have the same method. Then when two packages should be imported, only one package is imported.

gf cli 获取的 imports 是正确的,在通过 golang.org/x/tools/importsimports.Process(path, []byte(content), nil) fix imports 之后,会被修改为错误的 imports
https://github.com/gogf/gf/blob/ee2cf92479a0575e07d3812d18b7eaea4fe10bbe/cmd/gf/internal/utility/utils/utils.go#L25C58-L25C58

@yzy613
Copy link

yzy613 commented Dec 7, 2023

@wheelergeo It seems that there's some improvement for this function. It should check line by line for the imports part of go file content, not for all content of go file. image image

I think the issue lies in the utils.GoFmt(in.DstFolder) part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. CLI about gf cli enhancement help wanted planned This issue/proposal is planned into our next steps.
Projects
None yet
Development

No branches or pull requests

4 participants