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

快速开始, 按照流程执行,生成代码时没有handler方法。 #1157

Closed
LF-DevJourney opened this issue Oct 15, 2024 · 12 comments
Closed
Labels
bug Something isn't working

Comments

@LF-DevJourney
Copy link

图片

@LF-DevJourney LF-DevJourney added the bug Something isn't working label Oct 15, 2024
@LF-DevJourney
Copy link
Author

11470@lf MINGW64 ~/Desktop/hertz_demo
$ hz --verbose update  -idl hello.thrift
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/app/app.go:86: Args: &config.Argument{CmdType:"update", Verbose:true, Cwd:"C:\\Users\\11470\\Desktop\\hertz_demo", OutDir:"C:\\Users\\11470\\Desktop\\hertz_demo", HandlerDir:"", ModelDir:"", RouterDir:"", ClientDir:"", BaseDomain:"", ForceClientDir:"", IdlType:"thrift", IdlPaths:[]string{"C:\\Users\\11470\\Desktop\\hertz_demo\\hello.thrift"}, RawOptPkg:[]string(nil), OptPkgMap:map[string]string{}, Includes:[]string(nil), PkgPrefix:"", Gopath:"C:\\Users\\11470\\go", Gosrc:"C:\\Users\\11470\\go\\src", Gomod:"hertz/demo", Gopkg:"", ServiceName:"", Use:"", NeedGoMod:false, JSONEnumStr:false, QueryEnumAsInt:false, UnsetOmitempty:false, ProtobufCamelJSONTag:false, ProtocOptions:[]string(nil), ThriftOptions:[]string(nil), ProtobufPlugins:[]string(nil), ThriftPlugins:[]string(nil), SnakeName:false, RmTags:[]string(nil), Excludes:[]string(nil), NoRecurse:false, HandlerByMethod:false, ForceNew:false, SnakeStyleMiddleware:false, EnableExtends:false, SortRouter:false, CustomizeLayout:"", CustomizeLayoutData:"", CustomizePackage:"", ModelBackend:""}
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/config/cmd.go:39: [DEBUG]path:C:\Users\11470\go\bin\thriftgo.exe
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/util/tool_install.go:141: current thriftgo version is 0.3.17
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/config/cmd.go:170: thriftgo -v -o C:\Users\11470\Desktop\hertz_demo\biz\model -g go:reserve_comments,gen_json_tag=false,package_prefix=hertz/demo/biz/model -p hertz=C:\Users\11470\go\bin\hz.exe:CmdType=update,Verbose=true,Cwd=C:\Users\11470\Desktop\hertz_demo,OutDir=C:\Users\11470\Desktop\hertz_demo,IdlType=thrift,IdlPaths=C:\Users\11470\Desktop\hertz_demo\hello.thrift,Gopath=C:\Users\11470\go,Gosrc=C:\Users\11470\go\src,Gomod=hertz/demo -r C:\Users\11470\Desktop\hertz_demo\hello.thrift
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/app/app.go:420: begin to trigger plugin, compiler: thriftgo, idl_paths: [C:\Users\11470\Desktop\hertz_demo\hello.thrift]
[INFO] Generating: "go"
[INFO] option: reserve_comments=
[INFO] option: gen_json_tag=false
[INFO] option: package_prefix=hertz/demo/biz/model
[INFO] Processing hello.thrift
[INFO] Got 2 contents
[INFO] Run plugin "hertz"
[WARN] hertz stderr:
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/thrift/plugin.go:279: Processing hello.thrift
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/generator/template.go:283: Write biz\handler\hello\world\hello_service.go
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/generator/template.go:283: Write biz\router\hello\world\hello.go
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/generator/template.go:283: Write biz\router\hello\world\middleware.go
[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/generator/template.go:283: Write biz\router\register.go

[INFO] patch "C:\\Users\\11470\\Desktop\\hertz_demo\\biz\\model\\hello\\world\\hello.go" at "imports" with size 61
[INFO] Write C:\Users\11470\Desktop\hertz_demo\biz\model\hello\world\hello.go
[INFO] Write C:\Users\11470\Desktop\hertz_demo\biz\handler\hello\world\hello_service.go
[INFO] Write C:\Users\11470\Desktop\hertz_demo\biz\router\hello\world\hello.go
[INFO] Write C:\Users\11470\Desktop\hertz_demo\biz\router\hello\world\middleware.go
[INFO] Write C:\Users\11470\Desktop\hertz_demo\biz\router\register.go

[INFO]C:/Users/11470/go/pkg/mod/github.com/cloudwego/hertz/cmd/hz@v0.9.0/app/app.go:433: end run plugin thriftgo_gen_hertz

@rogerogers
Copy link
Contributor

需要有 service 才能生成 handler

@LF-DevJourney
Copy link
Author

对于初学者,快速开始文档给人的预期,就是按照文档流程可以运行起来。 初学者对之并没有一个整体的认识,并不知道缺少什么?

文档给人的感觉对初学者很不友好,初学者按文档来实践时遇到很多的问题。

@LF-DevJourney
Copy link
Author

handler中没有方法时,就会造成接下来的流程无法执行,因为导入的包没有使用,编译时就抛出错误。

@rogerogers
Copy link
Contributor

感谢反馈,后续我们优化下

@LF-DevJourney
Copy link
Author

上面图片中的idl文件中有service, 但是却没有生成的。

@GuangmingLuo
Copy link
Member

用 MAC 或者 WSL 试试,没有做过 windows 场景下的完整测试,部分文档针对 windows 可能需要更新和优化。

@rogerogers
Copy link
Contributor

#1158 应该是这个问题,没有定义 http 路径,我更新下

@LF-DevJourney
Copy link
Author

我尝试windows上的debian docker容器,一样的结果。

root@f5beb696f266:~/workspace# uname -a
Linux f5beb696f266 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 GNU/Linux
root@f5beb696f266:~/workspace#
root@f5beb696f266:~/workspace#
root@f5beb696f266:~/workspace#
root@f5beb696f266:~/workspace#
root@f5beb696f266:~/workspace# cat biz/handler/hello/world/hello_service.go
// Code generated by hertz generator.

package world

import (
        "context"

        "github.com/cloudwego/hertz/pkg/app"
        "github.com/cloudwego/hertz/pkg/protocol/consts"
)
root@f5beb696f266:~/workspace# cat hello.thrift
namespace go hello.world

service HelloService {
    string Hello(1: string name);
}


@LF-DevJourney
Copy link
Author

我明天试试非容器的debian, 或者mac看下。

@rogerogers
Copy link
Contributor

参考更新后的文档或者 https://www.cloudwego.io/docs/hertz/tutorials/toolkit/usage-thrift/ 这里,

service HelloService {
    string Hello(1: string name) (api.get="/hello");
}

@LF-DevJourney
Copy link
Author

谢谢,可以了。原来是idl写法存在问题。对这个不熟悉,生成代码过程中没有详细日志信息。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants