mirror of
https://github.com/restic/restic.git
synced 2026-11-26 07:19:49 +00:00
cmd/restic, limiter: Move config knowledge to internal packages
The GlobalOptions struct now embeds a backend.TransportOptions, so it doesn't need to construct one in open and create. The upload and download limits are similarly now a struct in internal/limiter that is embedded in GlobalOptions.
This commit is contained in:
1 parent
1dd4b9b60e
commit
90d2c0502b
4 files changed
+29
-38
No files matched your search
@@ -12,20 +12,27 @@ type staticLimiter struct {
|
||||
downstream *ratelimit.Bucket
|
||||
}
|
||||
|
||||
// Limits represents static upload and download limits.
|
||||
// For both, zero means unlimited.
|
||||
type Limits struct {
|
||||
UploadKb int
|
||||
DownloadKb int
|
||||
}
|
||||
|
||||
// NewStaticLimiter constructs a Limiter with a fixed (static) upload and
|
||||
// download rate cap
|
||||
func NewStaticLimiter(uploadKb, downloadKb int) Limiter {
|
||||
func NewStaticLimiter(l Limits) Limiter {
|
||||
var (
|
||||
upstreamBucket *ratelimit.Bucket
|
||||
downstreamBucket *ratelimit.Bucket
|
||||
)
|
||||
|
||||
if uploadKb > 0 {
|
||||
upstreamBucket = ratelimit.NewBucketWithRate(toByteRate(uploadKb), int64(toByteRate(uploadKb)))
|
||||
if l.UploadKb > 0 {
|
||||
upstreamBucket = ratelimit.NewBucketWithRate(toByteRate(l.UploadKb), int64(toByteRate(l.UploadKb)))
|
||||
}
|
||||
|
||||
if downloadKb > 0 {
|
||||
downstreamBucket = ratelimit.NewBucketWithRate(toByteRate(downloadKb), int64(toByteRate(downloadKb)))
|
||||
if l.DownloadKb > 0 {
|
||||
downstreamBucket = ratelimit.NewBucketWithRate(toByteRate(l.DownloadKb), int64(toByteRate(l.DownloadKb)))
|
||||
}
|
||||
|
||||
return staticLimiter{
|
||||
|
||||
Reference in new issue
Block a user