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

@@ -15,15 +15,18 @@ type Option interface {
}
type options struct {
timeout time.Duration
header http.Header
sign auth.Auth
signTTL int64
ctx context.Context
contentLength int64
masterMeta bool
endpoint *url.URL
slaveNodeID string
timeout time.Duration
header http.Header
sign auth.Auth
signTTL int64
ctx context.Context
contentLength int64
masterMeta bool
endpoint *url.URL
slaveNodeID string
tpsLimiterToken string
tps float64
tpsBurst int
}
type optionFunc func(*options)
@@ -37,6 +40,7 @@ func newDefaultOption() *options {
header: http.Header{},
timeout: time.Duration(30) * time.Second,
contentLength: -1,
ctx: context.Background(),
}
}
@@ -113,3 +117,15 @@ func WithEndpoint(endpoint string) Option {
o.endpoint = endpointURL
})
}
// WithTPSLimit 请求时使用全局流量限制
func WithTPSLimit(token string, tps float64, burst int) Option {
return optionFunc(func(o *options) {
o.tpsLimiterToken = token
o.tps = tps
if burst < 1 {
burst = 1
}
o.tpsBurst = burst
})
}