feat: tps limit for OneDrive policy

This commit is contained in:
HFO4
2022-06-09 16:11:36 +08:00
parent 4859ea6ee5
commit f083d52e17
9 changed files with 170 additions and 13 deletions

View File

@@ -34,13 +34,15 @@ type Client interface {
// HTTPClient 实现 Client 接口
type HTTPClient struct {
mu sync.Mutex
options *options
mu sync.Mutex
options *options
tpsLimiter TPSLimiter
}
func NewClient(opts ...Option) Client {
client := &HTTPClient{
options: newDefaultOption(),
options: newDefaultOption(),
tpsLimiter: globalTPSLimiter,
}
for _, o := range opts {
@@ -126,6 +128,10 @@ func (c *HTTPClient) Request(method, target string, body io.Reader, opts ...Opti
}
}
if options.tps > 0 {
c.tpsLimiter.Limit(options.ctx, options.tpsLimiterToken, options.tps, options.tpsBurst)
}
// 发送请求
resp, err := client.Do(req)
if err != nil {