Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorLog ¶
func ErrorLog() endpoint.Middleware
ErrorLog WARNING: 如果使用该中间件, 请务必注册于 Respond 之前
ErrorLog 会在 rpc 处理完请求之后对错误进行截取, 并进行日志的输出 ¶
ErrorLog 流程如下
- 如果错误为 nil 就直接返回
- 尝试将 err 转换为 errno, 如果成功就再判断是否需要输出调用栈
- 如果不是 errno, 说明这是一个不可控的 error, 但这里不对他进行处理, 打印返回即可
func Respond ¶
func Respond() endpoint.Middleware
Respond 会对所有的响应和 error 进行拦截 主要用于为 response 中的 BaseResponse 加上 code 和 msg (仅当 response 未设置且 error 为 errno) 让业务层不需要处理相关的操作, 只需要返回 error 即可.
Respond 流程如下:
- 尝试从 resp 中获取到真正的在 idl 中定义的 response (Ref: https://www.cloudwego.io/zh/docs/kitex/tutorials/framework-exten/middleware/)
- 获取到 response 后尝试从 response 中提取出来 model.BaseResp, 然后对其进行赋值
- 尝试判断 err 是否为 errno, 如果是的话说明这是一个可控的 error, 我们对外部返回 nil 即可 (// TODO explain)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.