请求结果命中缓存, 记录响应日志

This commit is contained in:
2025-04-25 16:25:13 +08:00
parent 78f6b61d65
commit 9bd3030cb8
2 changed files with 8 additions and 5 deletions

View File

@ -106,11 +106,11 @@ func NewHttpClient(reqConfig *define.Request, cacheInstance cache.ICache) (*Http
hc.OnRequestFinish(func(req *define.Request, rep *define.Response) {
if rep.IsSuccess {
// 请求成功
log.Record(req.Ctx, req.Logger, consts.LogLevelInfo, "接口请求成功", req, rep)
log.Record(consts.LogLevelInfo, "接口请求成功", req, rep)
return
}
// 请求失败
log.Record(req.Ctx, req.Logger, consts.LogLevelError, "接口请求失败", req, rep)
log.Record(consts.LogLevelError, "接口请求失败", req, rep)
})
return hc, nil
}
@ -292,6 +292,8 @@ func (hc *HttpClient) Request() *define.Response {
_ = hc.requestBackendApi()
}()
}()
// 命中缓存必然请求成功, 直接记录成功日志即可
log.Record(consts.LogLevelInfo, "接口请求成功:命中缓存", hc.reqConfig, cacheResult)
return cacheResult
}