go微服务开发:go-zero中间件

还是以演示工程为例,中间件定义在search模块的search.api文件,代码如下:

type (
	SearchReq {
		// 图书名称
		Name string `form:"name"`
	}

	SearchReply {
		Name  string `json:"name"`
		Count int    `json:"count"`
	}
)

@server(
	jwt: Auth
	middleware : Example
)
service search-api  {
	@handler search
	get /search/do  (SearchReq)     returns (SearchReply)
}

service search-api  {
	@handler ping
	get /search/ping
}

  cd service\search\api,执行生成api服务的命令:

goctl api go -api search.api -dir .

  因为在search.api定义了中间件Example,生成api服务时会自动生成中间件的代码

posted @ 2023-03-16 21:01  jamstack  阅读(20)  评论(0编辑  收藏  举报