middleware

package
v0.0.0-...-ccdcda8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

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 流程如下

  1. 如果错误为 nil 就直接返回
  2. 尝试将 err 转换为 errno, 如果成功就再判断是否需要输出调用栈
  3. 如果不是 errno, 说明这是一个不可控的 error, 但这里不对他进行处理, 打印返回即可

func Respond

func Respond() endpoint.Middleware

Respond 会对所有的响应和 error 进行拦截 主要用于为 response 中的 BaseResponse 加上 code 和 msg (仅当 response 未设置且 error 为 errno) 让业务层不需要处理相关的操作, 只需要返回 error 即可.

Respond 流程如下:

  1. 尝试从 resp 中获取到真正的在 idl 中定义的 response (Ref: https://www.cloudwego.io/zh/docs/kitex/tutorials/framework-exten/middleware/)
  2. 获取到 response 后尝试从 response 中提取出来 model.BaseResp, 然后对其进行赋值
  3. 尝试判断 err 是否为 errno, 如果是的话说明这是一个可控的 error, 我们对外部返回 nil 即可 (// TODO explain)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL