MCPcopy Index your code
hub / github.com/cloudfoundry/cli / ToMegabytes

Function ToMegabytes

cf/formatters/bytes.go:49–74  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

47}
48
49func ToMegabytes(s string) (int64, error) {
50 parts := bytesPattern.FindStringSubmatch(strings.TrimSpace(s))
51 if len(parts) < 3 {
52 return 0, invalidByteQuantityError()
53 }
54
55 value, err := strconv.ParseInt(parts[1], 10, 0)
56 if err != nil {
57 return 0, invalidByteQuantityError()
58 }
59
60 var bytes int64
61 unit := strings.ToUpper(parts[2])
62 switch unit {
63 case "T":
64 bytes = value * TERABYTE
65 case "G":
66 bytes = value * GIGABYTE
67 case "M":
68 bytes = value * MEGABYTE
69 case "K":
70 bytes = value * KILOBYTE
71 }
72
73 return bytes / MEGABYTE, nil
74}
75
76var (
77 bytesPattern = regexp.MustCompile(`(?i)^(-?\d+)([KMGT])B?$`)

Callers 8

ExecuteMethod · 0.92
ExecuteMethod · 0.92
ExecuteMethod · 0.92
ExecuteMethod · 0.92
ExecuteMethod · 0.92
bytesValFunction · 0.92
bytes_test.goFile · 0.85

Calls 1

invalidByteQuantityErrorFunction · 0.85

Tested by

no test coverage detected