-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
50 lines (40 loc) · 871 Bytes
/
utils.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package wlbdqm
import (
"errors"
"log"
"math"
"strconv"
)
func DebugPrintln(vs ...interface{}) {
if appMode == AppModeDebug {
vs = append([]interface{}{"[debug] "}, vs...)
log.Println(vs...)
}
}
func ErrorPrintln(vs ...interface{}) {
vs = append([]interface{}{"[error] "}, vs...)
log.Println(vs...)
}
func InfoPrintln(vs ...interface{}) {
vs = append([]interface{}{"[info] "}, vs...)
log.Println(vs...)
}
var units = []byte{'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'}
func ParseSizeToByte(s string) (float64, error) {
n := len(s)
unit := s[n-1]
var part float64
for i, v := range units {
if v == unit {
part = math.Pow(1024, float64(i+1))
}
}
if part <= 0 {
return 0, errors.New("unit not found")
}
coef, err := strconv.ParseFloat(s[:n-1], 64)
if err != nil {
return 0, errors.New("parse size error")
}
return coef * part, nil
}