使用示例
简单示例
以 hz
工具生成的项目为例:
生成步骤参考 hz 使用(thrift)
项目目录结构如下:
含有路由注册代码的文件如下:
- router.go
// Code generated by hertz generator.
package main
import (
handler "example.com/m/biz/handler"
"github.com/cloudwego/hertz/pkg/app/server"
)
// customizeRegister registers customize routers.
func customizedRegister(r *server.Hertz) {
r.GET("/ping", handler.Ping)
// your code ...
}
- biz/router/hello/example/hello.go
// Code generated by hertz generator. DO NOT EDIT.
package example
import (
example "example.com/m/biz/handler/hello/example"
"github.com/cloudwego/hertz/pkg/app/server"
)
/*
This file will register all the routes of the services in the master idl.
And it will update automatically when you use the "update" command for the idl.
So don't modify the contents of the file, or your code will be deleted when it is updated.
*/
// Register register routes based on the IDL 'api.${HTTP Method}' annotation.
func Register(r *server.Hertz) {
root := r.Group("/", rootMw()...)
root.GET("/hello", append(_hellomethodMw(), example.HelloMethod)...)
}
现在在项目根目录执行 api-list
命令
cwgo api-list
或 cwgo api-list --project_path .
输出效果如下:
最后修改
September 20, 2024
: doc: sync Thriftgo 反射使用文档 (#1144) (f9b36e0)