feat: tps limit for OneDrive policy
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user