diff options
Diffstat (limited to '_____/utils/size.go')
-rw-r--r-- | _____/utils/size.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/_____/utils/size.go b/_____/utils/size.go new file mode 100644 index 00000000..176cc9e1 --- /dev/null +++ b/_____/utils/size.go @@ -0,0 +1,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 +} |