Skip to content

Commit

Permalink
feat: validate rate limit
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Jun 16, 2022
1 parent a7b4b92 commit a139aa3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/config/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (cfg *ClientOption) Validate() error {
}

if int64(cfg.RateLimit.Limit) < DefaultMinRate.ToNumber() {
return fmt.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
return errors.Wrapf(dferrors.ErrInvalidHeader, "rate limit must be greater than %s", DefaultMinRate.String())
}

return nil
Expand Down
5 changes: 4 additions & 1 deletion client/config/dfget_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package config

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

var dfgetConfig = ClientOption{
URL: "",
Expand Down
4 changes: 2 additions & 2 deletions client/config/peerhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ func (p *DaemonOption) Validate() error {
}

if int64(p.Download.TotalRateLimit.Limit) < DefaultMinRate.ToNumber() {
return fmt.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
return errors.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
}

if int64(p.Upload.RateLimit.Limit) < DefaultMinRate.ToNumber() {
return fmt.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
return errors.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
}

switch p.Download.DefaultPattern {
Expand Down

0 comments on commit a139aa3

Please sign in to comment.