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

fix: fixed goctl api go --home parameter error when loading non-exist… #3319

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

elza2
Copy link
Contributor

@elza2 elza2 commented Jun 5, 2023

Describe the bug
image

goctl api go -api ./api/apis/hello.api --dir ./app --home ./api/.goctl

app/etc/test-api.yaml exists, ignored generation
app/internal/config/config.go exists, ignored generation
app/test.go exists, ignored generation
app/internal/svc/servicecontext.go exists, ignored generation
2023/06/05 11:57:01 open api/.goctl/1.5.3/api: no such file or directory

the 1.5.3 path is inexplicably found in the file path, causing the generation failure.
By viewing the goctl source code, find the tools/goctl/util/pathx/file.go 148 line, beforeTemplateDir does not exist.

 beforeTemplateDir := filepath.Join(home, version.GetGoctlVersion(), category)
 entries, err := os.ReadDir(beforeTemplateDir)
 if err != nil {
	return "", err
 }

The original code submission history for comparison found that err is not processed, is ignored.
After modification, the run was found to be successful.

goctl api go -api ./api/apis/hello.api --dir ./app --home ./api/.goctl

app/etc/test-api.yaml exists, ignored generation
app/internal/config/config.go exists, ignored generation
app/test.go exists, ignored generation
app/internal/svc/servicecontext.go exists, ignored generation
Done.

@lxy1992
Copy link
Contributor

lxy1992 commented Jun 5, 2023

I meet this same problem today, but I suggest to fix this problem in a positive way.

@codecov
Copy link

codecov bot commented Jun 5, 2023

Codecov Report

Merging #3319 (45a55c2) into master (2831432) will decrease coverage by 0.02%.
The diff coverage is n/a.

see 1 file with indirect coverage changes

@kesonan
Copy link
Collaborator

kesonan commented Jun 7, 2023

Please fix the error in loop at https://github.com/zeromicro/go-zero/blob/master/tools/goctl/util/pathx/file.go#L155 as follows:

for _, entry := range entries {
	info, err := entry.Info()
	if err != nil {
		continue
	}
	infos = append(infos, info)
}

@elza2
Copy link
Contributor Author

elza2 commented Jun 8, 2023

Please fix the error in loop at https://github.com/zeromicro/go-zero/blob/master/tools/goctl/util/pathx/file.go#L155 as follows:

for _, entry := range entries {
	info, err := entry.Info()
	if err != nil {
		continue
	}
	infos = append(infos, info)
}

Hi, it has been repaired, please check it.

@elza2
Copy link
Contributor Author

elza2 commented Jun 9, 2023

Please fix the error in loop at https://github.com/zeromicro/go-zero/blob/master/tools/goctl/util/pathx/file.go#L155 as follows:

for _, entry := range entries {
	info, err := entry.Info()
	if err != nil {
		continue
	}
	infos = append(infos, info)
}

Hi, it has been repaired, please check it.

@anqiansong

Copy link
Collaborator

@kesonan kesonan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevwan kevwan added this pull request to the merge queue Jun 12, 2023
Merged via the queue into zeromicro:master with commit 4a29a0b Jun 12, 2023
4 checks passed
wuyazi pushed a commit to wuyazi/go-zero that referenced this pull request Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants