支持设置流控实例
This commit is contained in:
parent
06587ace43
commit
2d08e9a629
@ -9,6 +9,7 @@ package define
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ type Request struct {
|
|||||||
ReadTimeout int64 `json:"read_timeout"` // 读取超时时间
|
ReadTimeout int64 `json:"read_timeout"` // 读取超时时间
|
||||||
RetryRule *RequestRetryRule `json:"retry_rule"` // 重试规则
|
RetryRule *RequestRetryRule `json:"retry_rule"` // 重试规则
|
||||||
Logger *zap.Logger `json:"-"` // 日志记录器
|
Logger *zap.Logger `json:"-"` // 日志记录器
|
||||||
|
RateLimiter resty.RateLimiter `json:"-"` // 流控实例
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestRetryRule 重试规则
|
// RequestRetryRule 重试规则
|
||||||
|
@ -31,6 +31,10 @@ func NewRestyClient(reqConfig *define.Request) (*resty.Client, *resty.Request) {
|
|||||||
if nil == reqConfig {
|
if nil == reqConfig {
|
||||||
return client, request
|
return client, request
|
||||||
}
|
}
|
||||||
|
if nil != reqConfig.RateLimiter {
|
||||||
|
// 设置流控实例
|
||||||
|
client.SetRateLimiter(reqConfig.RateLimiter)
|
||||||
|
}
|
||||||
formatHeader(reqConfig)
|
formatHeader(reqConfig)
|
||||||
client.SetAllowGetMethodPayload(true) // 配置 GET 请求允许带 Body
|
client.SetAllowGetMethodPayload(true) // 配置 GET 请求允许带 Body
|
||||||
client.SetJSONMarshaler(json.Marshal) // 序列化方法
|
client.SetJSONMarshaler(json.Marshal) // 序列化方法
|
||||||
|
Loading…
x
Reference in New Issue
Block a user