hz usage(thrift)
Create a project based on thrift IDL
new: Create a new project
-
Create the thrift IDL file in the current directory
-
Create a new project
-
Modify the handler and add your own logic
-
Compile the project
-
Run the project and test it
Run the project:
Test:
If it returns
{"RespBody":"hello,hertz"}
, it works.
update: Update an existing project
-
If your thrift IDL is updated, for example:
-
Switch to the directory where the new command was executed and update the modified thrift IDL
Note:
-
When writing the update command, you only need to specify the IDL file that defines the
service
. hz will automatically generate all the dependencies for that file. -
As you can see
Add new method under
biz/handler/hello/example/hello_service.go
The filenew_service.go
and the corresponding “NewMethod” method have been added underbiz/handler/hello/example
.Now let’s develop the “OtherMethod” interface:
-
Compile the project
-
Run the project and test it
Run the project:
Test:
If it returns
{"Resp":"Other method: other method"}
, it works.
For more example code, please refer to code.