zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
29.38k stars 3.97k forks source link

goctl: go work support #4332

Open ningzio opened 3 months ago

ningzio commented 3 months ago

Is your feature request related to a problem? Please describe.

when creating new project using goctl api new xxx inside of a go workspace, it will failed: "no matched module"

Describe the solution you'd like

goctl can auto detect go workspace, if new project is inside of a go workspace, goctl should handle it, make sure the project is created.

Describe alternatives you've considered

Additional context

goctl use go list -json -m to find current project's go module here, but in go workspace, this command only returns modules that declared in go.work.

I tried add project into go.work after go mod is initialized, and it works.

maybe this is not the best practice but hope it can to be helpful.

image

btw, I find goctl use go list -m -f '{{.GoMod}}' to check if the current path is a go module here, but in go workspace, this command could be inaccurate. go env GOMOD should be better? if the current path is not a go module, it will return "/dev/null".

ningzio commented 3 months ago

this can be resolved by add new project to go.work manually, but it would be nice that goctl can do it for us :)

kevwan commented 3 months ago

Would you please contribute a PR on this?

ningzio commented 2 months ago

Would you please contribute a PR on this?

sure, I would love to.