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

cli gen service:BUG #2310

Closed
alaywn opened this issue Nov 17, 2022 · 5 comments · Fixed by #3488
Closed

cli gen service:BUG #2310

alaywn opened this issue Nov 17, 2022 · 5 comments · Fixed by #3488
Labels
help wanted planned This issue/proposal is planned into our next steps.

Comments

@alaywn
Copy link
Contributor

alaywn commented Nov 17, 2022

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

go version go1.19.3 darwin/arm64

2. What version of GoFrame are you using?

github.com/gogf/gf/v2 v2.2.4

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

YES!

4. What did you do?

BUG1:使用gf gen service时,logic目录下的代码中被注释的方法,依旧会在service中生成接口方法
BUG2:使用gf gen service时,如果service中已经生成的了文件,再回提示no dirty信息,无法重新生成覆盖已有文件(参数overwrite=true)

BUG1复现方式:focus-single项目中,注释某个logic目录中的方法,然后运行gf gen service 就可以重现
BUG2复现方式:focus-single项目中直接运行gf gen service 就可以重现

5. What did you expect to see?

6. What did you see instead?

@zcyc
Copy link
Contributor

zcyc commented Nov 21, 2022

logic 目录下的文件,没有 struct 也会生成 service。

@gqcn gqcn added the planned This issue/proposal is planned into our next steps. label Jan 18, 2023
@sanrentai
Copy link
Contributor

sanrentai commented Mar 2, 2023

遇到同样的问题,v2.3.2
应该是下面这里的问题,但我不会改正则,
genservice_calculate.go

matches, err = gregex.MatchAllString(`func \((.+?)\) ([\s\S]+?) {`, fileContent)

把注释行去除,改成

	fileContent2 := ""
	fileContentLines := gstr.Split(fileContent, "\n")
	for _, line := range fileContentLines {
		if gstr.HasPrefix(line, "//") {
			continue
		}
		fileContent2 += line + "\n"
	}
	matches, err := gregex.MatchAllString(`func \((.+?)\) ([\s\S]+?) {`, fileContent2)

@gqcn

sanrentai added a commit to sanrentai/gf-1 that referenced this issue Mar 2, 2023
sanrentai added a commit to sanrentai/gf-1 that referenced this issue Mar 2, 2023
@gqcn
Copy link
Member

gqcn commented Mar 3, 2023

@alaywn @zcyc @sanrentai 大家好,其实这个gen service命令内部是使用正则匹配来实现方法的搜集和生成的,目前并没有识别注释的逻辑。所以这里改进的话可以增加相关逻辑即可,也比较简单。
另外一种更优雅的代码生成方式,是通过官方的Golang语法解析包解析源代码来生成代码,这种方式会稍微复杂一些,但是确实优雅、非常优雅!
感兴趣的小伙伴可以一起参与建设。

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

Hello @alaywn. 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!
你好 @alaywn。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

sanrentai added a commit to sanrentai/gf-1 that referenced this issue Mar 3, 2023
gqcn pushed a commit that referenced this issue Mar 13, 2023
@oldme-git
Copy link
Member

Please show #3067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted planned This issue/proposal is planned into our next steps.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants