chore: Update bandwidth convertor

Sync with 6d6a26b399
This commit is contained in:
H1JK 2023-12-08 21:22:20 +08:00 committed by wwqgtxx
parent 262d3295d1
commit 582ac28728

View file

@ -140,24 +140,25 @@ func StringToBps(s string) uint64 {
if m == nil { if m == nil {
return 0 return 0
} }
var n uint64 var n uint64 = 1
switch m[2] { switch m[2] {
case "K":
n = 1 << 10
case "M":
n = 1 << 20
case "G":
n = 1 << 30
case "T": case "T":
n = 1 << 40 n *= 1000
default: fallthrough
n = 1 case "G":
n *= 1000
fallthrough
case "M":
n *= 1000
fallthrough
case "K":
n *= 1000
} }
v, _ := strconv.ParseUint(m[1], 10, 64) v, _ := strconv.ParseUint(m[1], 10, 64)
n = v * n n *= v
if m[3] == "b" { if m[3] == "b" {
// Bits, need to convert to bytes // Bits, need to convert to bytes
n = n >> 3 n /= 8
} }
return n return n
} }