Documentation ¶
Overview ¶
Package http 提供基础 http 客户端组件
本包通过替换 http.DefaultTransport 实现以下功能: - 日志(logging) - 链路追踪(tracing) - 指标监控(metrics)
请务必使用 http.NewRequestWithContext 构造 req 对象,这样才能传递 ctx 信息。
如果希望使用自定义 Transport,需要将 RoundTrip 的逻辑 最终委托给 http.DefaultTransport
使用示例:
req, _ := http.NewRequestWithContext(ctx, method, url, body) c := &http.Client{ Timeout: 1 * time.Second, } resp, err := c.Do(req)
Click to show internal directories.
Click to hide internal directories.