diff options
author | Wolfy-J <[email protected]> | 2018-06-03 12:54:43 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-03 12:54:43 +0300 |
commit | 36ea77baa5a41de10bd604cd0e5b5b3cafaaeb64 (patch) | |
tree | 13ca8abd454a6668f490eec2e44b1520bd3953fe /utils | |
parent | b02611b7266589d888e054a1d2e4432ae370617d (diff) |
service bus, http service, rpc bus, cli commands, new configs
Diffstat (limited to 'utils')
-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 +} |