Missing possible error handlings... But still should work...
(size string)
| 8 | |
| 9 | // Missing possible error handlings... But still should work... |
| 10 | func ConvertStringToBytes(size string) int64 { |
| 11 | sizes := []string{"Bytes", "KB", "MB", "GB", "TB"} |
| 12 | |
| 13 | parts := strings.Split(size, " ") |
| 14 | value, err := strconv.ParseFloat(parts[0], 64) |
| 15 | |
| 16 | if err != nil { |
| 17 | return 0 |
| 18 | } |
| 19 | |
| 20 | var unit string = parts[1] |
| 21 | var index int = IndexOf(unit, sizes) |
| 22 | |
| 23 | if index == -1 { |
| 24 | return 0 |
| 25 | } |
| 26 | |
| 27 | return int64(value * math.Pow(1024, float64(index))) |
| 28 | |
| 29 | } |
no test coverage detected