Documentation
¶
Index ¶
- type Client
- type MetricData
- type MetricRecorder
- type Option
- func WithDisableLog() Option
- func WithIdleConnTimeout(timeout time.Duration) Option
- func WithInsecureSkipVerify() Option
- func WithKeepAlive(duration time.Duration) Option
- func WithLogger(l logger.Logger) Option
- func WithMaxBodyLogSize(size int64) Option
- func WithMaxIdleConns(count int) Option
- func WithMetric(recorder MetricRecorder) Option
- func WithRetry(count int, waitTime, maxWaitTime time.Duration) Option
- func WithTLSHandshakeTimeout(timeout time.Duration) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTrace(serviceName string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MetricData ¶
type MetricData struct {
// 基础信息
Method string // HTTP 方法
Host string // 主机名
Path string // 请求路径
StatusCode int // HTTP 状态码
// 时间指标(来自 Resty TraceInfo)
TotalTime time.Duration // 总耗时
DNSLookup time.Duration // DNS 查询时间
TCPConn time.Duration // TCP 连接时间
TLSHandshake time.Duration // TLS 握手时间
ServerTime time.Duration // 服务器处理时间
ResponseTime time.Duration // 响应传输时间
// 连接信息
IsConnReused bool // 连接是否复用
IsConnWasIdle bool // 连接是否空闲
ConnIdleTime time.Duration // 连接空闲时间
RequestAttempt int // 请求尝试次数
RemoteAddr string // 远程地址
}
MetricData HTTP 请求的详细指标数据
type MetricRecorder ¶
type MetricRecorder interface {
// RecordRequest 记录 HTTP 请求指标
// 实现者可以将数据发送到 Prometheus、SigNoz 或其他监控系统
RecordRequest(data MetricData)
}
MetricRecorder HTTP 请求指标记录器接口
type Option ¶
type Option func(*options)
Option 配置选项函数
func WithIdleConnTimeout ¶
WithIdleConnTimeout 设置空闲连接超时时间
func WithInsecureSkipVerify ¶
func WithInsecureSkipVerify() Option
WithInsecureSkipVerify 跳过 TLS 证书验证(不推荐在生产环境使用)
func WithKeepAlive ¶
WithKeepAlive 设置 keep-alive 时间
func WithMaxBodyLogSize ¶
WithMaxBodyLogSize 设置最大 body 日志大小
func WithTLSHandshakeTimeout ¶
WithTLSHandshakeTimeout 设置 TLS 握手超时时间
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
01_basic
command
|
|
|
02_with_trace
command
|
|
|
03_with_metric
command
|
|
|
04_production
command
|
|
|
05_file_operations
command
|
|
|
06_insecure_skip_verify
command
|
Click to show internal directories.
Click to hide internal directories.