我是 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
}
}
}
如何编写一个测试来测试当我向添加此拦截器的服务器发送请求时,请求和响应是否被正确记录?