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

Error occurred when executing gf gen service #2734

Closed
windvalley opened this issue Jul 4, 2023 · 0 comments
Closed

Error occurred when executing gf gen service #2734

windvalley opened this issue Jul 4, 2023 · 0 comments
Labels
done This issue is done, which may be release in next version. enhancement

Comments

@windvalley
Copy link
Contributor

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

go version go1.20.4 darwin/amd64

2. What version of GoFrame are you using?

goframe: v2.4.4

gf cli: v2.4.4

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

yes

4. What did you do?

$ gf gen service

报错如下:

not dirty, ignore generating service go file: internal/service/demo.go
not dirty, ignore generating service go file: internal/service/middleware.go
logicPackageName: logic, logicFilePath: internal/logic/logic.go, importPath: gf2-demo/internal/logic, importStr: _ "gf2-demo/internal/logic", mailFilePath: , mainFileContent:
exception recovered: runtime error: index out of range [1] with length 0
1. exception recovered: runtime error: index out of range [1] with length 0
   1).  github.com/gogf/gf/v2/os/gcmd.(*Command).doRun.func1
        /Users/xg/github/gf/os/gcmd/gcmd_command_run.go:111
   2).  go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End.func1
        /Users/xg/go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.7.0/trace/span.go:359
   3).  go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End
        /Users/xg/go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.7.0/trace/span.go:398
   4).  github.com/gogf/gf/cmd/gf/v2/internal/cmd/genservice.CGenService.checkAndUpdateMain
        /Users/xg/github/gf/cmd/gf/internal/cmd/genservice/genservice.go:337
   5).  github.com/gogf/gf/cmd/gf/v2/internal/cmd/genservice.CGenService.Service
        /Users/xg/github/gf/cmd/gf/internal/cmd/genservice/genservice.go:310
   6).  github.com/gogf/gf/v2/os/gcmd.newCommandFromMethod.func1
        /Users/xg/github/gf/os/gcmd/gcmd_command_object.go:324
   7).  github.com/gogf/gf/v2/os/gcmd.(*Command).doRun
        /Users/xg/github/gf/os/gcmd/gcmd_command_run.go:152
   8).  github.com/gogf/gf/v2/os/gcmd.(*Command).RunWithValueError
        /Users/xg/github/gf/os/gcmd/gcmd_command_run.go:91
   9).  github.com/gogf/gf/v2/os/gcmd.(*Command).RunWithError
        /Users/xg/github/gf/os/gcmd/gcmd_command_run.go:69
   10). github.com/gogf/gf/cmd/gf/v2/gfcmd.(*Command).Run
        /Users/xg/github/gf/cmd/gf/gfcmd/gfcmd.go:62
   11). main.main
        /Users/xg/github/gf/cmd/gf/main.go:27

查看gf最新版源码发现https://github.com/gogf/gf/blob/master/cmd/gf/internal/cmd/genservice/genservice.gocheckAndUpdateMain函数, 将项目程序入口文件默认为了项目根路径下的main.go, 而我的项目的入口文件是cmd/gf2-demo-api/gf2-demo-api.go, 从而导致后续代码报错.

不知道能否考虑兼容一下入口文件在cmd/下的这种使用方式, 目前看这种应该还算比较主流.

我这边想到的最简单的兼容方法是在生成完service代码文件进入checkAndUpdateMain后, 如果发现项目跟路径下没有main.go文件, 就忽略后续处理, 提前返回即可.

windvalley added a commit to windvalley/gf that referenced this issue Jul 4, 2023
Make the `gf gen service` command compatible with the scenario where the program entry file is located in the cmd/ directory. i.e.:

```
$ tree .
.
├── cmd
│   ├── gf2-demo-api
│   │   └── gf2-demo-api.go
│   └── gf2-demo-cli
│       └── gf2-demo-cli.go
```
gqcn added a commit that referenced this issue Jul 4, 2023
@gqcn gqcn added enhancement done This issue is done, which may be release in next version. labels Jul 4, 2023
@gqcn gqcn closed this as completed Jul 4, 2023
gqcn added a commit that referenced this issue Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done This issue is done, which may be release in next version. enhancement
Projects
None yet
Development

No branches or pull requests

2 participants