hz 使用 (thrift)
hz 使用 (thrift)。
基于 thrift IDL 创建项目
new: 创建一个新项目
-
在当前目录下创建 thrift idl 文件
-
创建新项目
-
修改 handler,添加自己的逻辑
-
编译项目
-
运行项目并测试
运行项目:
测试:
如果返回
{"RespBody":"hello,hertz"}
,说明接口调通。
update: 更新一个已有的项目
-
如果你的 thrift idl 有更新,例如:
-
切换到执行 new 命令的目录,更新修改后的 thrift idl
注意:
- 与 protobuf 不同,在编写 update 命令时,只需要指定定义
service
的 IDL 文件,hz 会自动将该文件的所有依赖文件都进行生成。
- 与 protobuf 不同,在编写 update 命令时,只需要指定定义
-
可以看到
在
biz/handler/hello/example/hello_service.go
下新增了新的方法
在biz/handler/hello/example
下新增了文件new_service.go
以及对应的 “NewMethod” 方法。下面我们来开发 “OtherMethod” 接口:
-
编译项目
-
运行项目并测试
运行项目:
测试:
如果返回
{"Resp":"Other method: other method"}
,说明接口调通。
更多示例代码请参考 code。
最后修改
January 13, 2025
: Update release-v0_12_0.md (#1203) (72c8d84)