提交 f55f1b83 authored 作者: mooncake9527's avatar mooncake9527

update

上级 6bcf8762
......@@ -14,7 +14,7 @@ import (
var (
GinContextKey = "gin_context"
ContextTraceIDKey = "traceID"
ContextTraceIDKey = "X-Request-ID"
KeyConfigFile = "config_file"
KeyConfigCenter = "config_center"
......
......@@ -296,7 +296,10 @@ func (req *Request) send(ctx context.Context, body io.Reader, buf *bytes.Buffer)
if req.err != nil {
return nil, req.err
}
if buf != nil {
requestID := xctx.CtxRequestID(ctx)
ctx = context.WithValue(ctx, fmt.Sprintf("oapi-req-%s", requestID), buf.String())
}
if req.customRequest != nil {
req.customRequest(req.request, buf)
}
......@@ -338,9 +341,11 @@ func (req *Request) send(ctx context.Context, body io.Reader, buf *bytes.Buffer)
if err != nil {
return xerror.New(err.Error())
}
logger.Info("httpcli rsp", logger.Any("body", bytes.NewBuffer(body).String()), xctx.CtxTraceIDField(ctx))
bodyBuf := bytes.NewBuffer(body)
ctx = context.WithValue(ctx, fmt.Sprintf("oapi-rsp-%s", xctx.CtxRequestID(ctx)), buf.String())
logger.Info("httpcli rsp", logger.Any("body", bodyBuf.String()), xctx.CtxTraceIDField(ctx))
if body != nil {
resp.Body = io.NopCloser(bytes.NewBuffer(body))
resp.Body = io.NopCloser(bodyBuf)
}
}
return nil
......@@ -365,9 +370,11 @@ func (req *Request) send(ctx context.Context, body io.Reader, buf *bytes.Buffer)
if e != nil {
err = xerror.New(e.Error())
}
logger.Info("httpcli rsp", logger.Any("body", bytes.NewBuffer(body).String()), xctx.CtxTraceIDField(ctx))
bodyBuf := bytes.NewBuffer(body)
ctx = context.WithValue(ctx, fmt.Sprintf("oapi-rsp-%s", xctx.CtxRequestID(ctx)), buf.String())
logger.Info("httpcli rsp", logger.Any("body", bodyBuf.String()), xctx.CtxTraceIDField(ctx))
if body != nil {
resp.Body = io.NopCloser(bytes.NewBuffer(body))
resp.Body = io.NopCloser(bodyBuf)
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论