fix panic on single digit throttles values

This commit is contained in:
Marcel Battista 2021-10-19 13:10:43 +02:00
parent 8ff3fb9b89
commit d372fa1fa4
1 changed files with 7 additions and 1 deletions

View File

@ -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)))