Skip to content

Commit

Permalink
fix: dfget ratelimit params (#1391)
Browse files Browse the repository at this point in the history
Signed-off-by: ljx373327 <[email protected]>
  • Loading branch information
1037husterljx authored Jun 16, 2022
1 parent bcb9f52 commit 2b42308
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions client/config/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"time"

"github.com/pkg/errors"
"golang.org/x/time/rate"

"d7y.io/dragonfly/v2/client/clientutil"
"d7y.io/dragonfly/v2/cmd/dependency/base"
"d7y.io/dragonfly/v2/internal/dferrors"
logger "d7y.io/dragonfly/v2/internal/dflog"
Expand Down Expand Up @@ -103,7 +103,7 @@ type ClientOption struct {
// WorkHome is working directory of dfget.
WorkHome string `yaml:"workHome,omitempty" mapstructure:"workHome,omitempty"`

RateLimit rate.Limit `yaml:"rateLimit,omitempty" mapstructure:"rateLimit,omitempty"`
RateLimit clientutil.RateLimit `yaml:"rateLimit,omitempty" mapstructure:"rateLimit,omitempty"`

// Config file paths,
// default:["/etc/dragonfly/dfget.yaml","/etc/dragonfly.conf"].
Expand Down
18 changes: 12 additions & 6 deletions client/config/dfget_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@

package config

import "d7y.io/dragonfly/v2/pkg/unit"
import (
"d7y.io/dragonfly/v2/client/clientutil"
"d7y.io/dragonfly/v2/pkg/unit"
"golang.org/x/time/rate"
)

var dfgetConfig = ClientOption{
URL: "",
Output: "",
Timeout: 0,
BenchmarkRate: 128 * unit.KB,
RateLimit: 0,
URL: "",
Output: "",
Timeout: 0,
BenchmarkRate: 128 * unit.KB,
RateLimit: clientutil.RateLimit{
Limit: rate.Limit(DefaultTotalDownloadLimit),
},
Md5: "",
DigestMethod: "",
DigestValue: "",
Expand Down
11 changes: 8 additions & 3 deletions client/config/dfget_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@

package config

import "d7y.io/dragonfly/v2/client/clientutil"

var dfgetConfig = ClientOption{
URL: "",
Output: "",
Timeout: 0,
URL: "",
Output: "",
Timeout: 0,
RateLimit: clientutil.RateLimit{
Limit: rate.Limit(DefaultTotalDownloadLimit),
},
Md5: "",
DigestMethod: "",
DigestValue: "",
Expand Down
2 changes: 1 addition & 1 deletion client/dfget/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func newDownRequest(cfg *config.DfgetConfig, hdr map[string]string) *dfdaemon.Do
Url: cfg.URL,
Output: cfg.Output,
Timeout: uint64(cfg.Timeout),
Limit: float64(cfg.RateLimit),
Limit: float64(cfg.RateLimit.Limit),
DisableBackSource: cfg.DisableBackSource,
UrlMeta: &base.UrlMeta{
Digest: cfg.Digest,
Expand Down
2 changes: 1 addition & 1 deletion cmd/dfget/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func init() {

flagSet.Duration("timeout", dfgetConfig.Timeout, "Timeout for the downloading task, 0 is infinite")

flagSet.String("limit", unit.Bytes(dfgetConfig.RateLimit).String(),
flagSet.String("ratelimit", unit.Bytes(dfgetConfig.RateLimit.Limit).String(),
"The downloading network bandwidth limit per second in format of G(B)/g/M(B)/m/K(B)/k/B, pure number will be parsed as Byte, 0 is infinite")

flagSet.String("digest", dfgetConfig.Digest,
Expand Down

0 comments on commit 2b42308

Please sign in to comment.