blob: 176cc9e18cdf03493c6a534b154bde72fd4e3727 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package utils
import (
"strconv"
"strings"
)
func ParseSize(size string) int64 {
if len(size) == 0 {
return 0
}
s, err := strconv.Atoi(size[:len(size)-1])
if err != nil {
return 0
}
switch strings.ToLower(size[len(size)-1:]) {
case "k", "kb":
return int64(s * 1024)
case "m", "mb":
return int64(s * 1024 * 1024)
case "g", "gb":
return int64(s * 1024 * 1024 * 1024)
}
return 0
}
|