go - 如何测试 Twirp 拦截器?
问题描述
我是 Go 和 Twirp 的新手。我正在研究一个现有的代码库,我正在尝试编写一个 Twirp 拦截器来记录每个请求和响应。
func LoggingInterceptor() twirp.Interceptor {
return func(next twirp.Method) twirp.Method {
return func(ctx context.Context, req interface{}) (interface{}, error) {
log := somepackage.GetLogger(ctx) //cannot share the implementation of somepackage, but this method is returning a logger that has an Info method defined on it
log.Info("Request received")
res, err := next(ctx, req)
log.Info("Response sent")
return res, err
}
}
}
如何编写一个测试来测试当我向添加此拦截器的服务器发送请求时,请求和响应是否被正确记录?
解决方案
推荐阅读
- node.js - 当我将十六进制转换为 ascii 字符时如何获得正确的值
- c# - 如何为新创建的 Workspace 指定 TargetFramework?
- vagrant-provision - 请求的 URL 未从 vagrantup 下载
- android - Android中具有干净架构的mvvm和没有干净架构的mvvm有什么区别?
- r - R count CSV 每一行的 NA 值的数量
- android - 如何让 android-app-module 识别和使用 gradle-plugin-module 源
- binning - 如何创建一个函数来为 pandas 数据框中的所有列创建 bin
- java - 如果没有消息出现,Vertx如何使消费者超时
- c++ - 有没有办法强制 LookupAccountSid 始终返回美国语言环境中的名称?
- google-cloud-platform - 设置 Google Storage 缓存控制元数据以允许转换