mirror of
https://github.com/schollz/croc.git
synced 2024-11-28 01:16:10 +03:00
fix panic on single digit throttles values
This commit is contained in:
parent
8ff3fb9b89
commit
d372fa1fa4
@ -178,7 +178,8 @@ func New(ops Options) (c *Client, err error) {
|
||||
|
||||
c.conn = make([]*comm.Comm, 16)
|
||||
|
||||
if len(c.Options.ThrottleUpload) > 0 && c.Options.IsSender {
|
||||
// initialize throttler
|
||||
if len(c.Options.ThrottleUpload) > 1 && c.Options.IsSender {
|
||||
upload := c.Options.ThrottleUpload[:len(c.Options.ThrottleUpload)-1]
|
||||
uploadLimit, err := strconv.ParseInt(upload, 10, 64)
|
||||
if err != nil {
|
||||
@ -193,6 +194,11 @@ func New(ops Options) (c *Client, err error) {
|
||||
uploadLimit = uploadLimit*1024*1024
|
||||
case "k", "K":
|
||||
uploadLimit = uploadLimit*1024
|
||||
default:
|
||||
uploadLimit, err = strconv.ParseInt(c.Options.ThrottleUpload, 10, 64)
|
||||
if err != nil {
|
||||
panic("Could not parse given Upload Limit")
|
||||
}
|
||||
}
|
||||
// Somehow 4* is neccessary
|
||||
rt = rate.Every(time.Second / (4*time.Duration(uploadLimit)))
|
||||
|
Loading…
Reference in New Issue
Block a user