-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.go
59 lines (45 loc) · 966 Bytes
/
core.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
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"os"
)
const (
SIZE_KiB = 1024
SIZE_MiB = 1048576
SIZE_GiB = 1073741824
SIZE_TiB = 1099511627776
)
func GetDir(path string) ([]os.FileInfo, error) {
f, err := os.Open(path)
defer f.Close()
if err != nil {
return nil, err
}
fileInfo, err := f.Readdir(-1)
if err != nil {
return nil, err
}
return fileInfo, nil
}
func main() {
LoadConfig()
ProcessCli()
}
///Helpers
func FormatSize(size int64) string {
if size < SIZE_KiB {
return fmt.Sprintf("%d Bytes", size)
} else if size < SIZE_MiB {
value := float64(size) / float64(SIZE_KiB)
return fmt.Sprintf("%.2f KiB", value)
} else if size < SIZE_GiB {
value := float64(size) / float64(SIZE_MiB)
return fmt.Sprintf("%.2f MiB", value)
} else if size < SIZE_TiB {
value := float64(size) / float64(SIZE_GiB)
return fmt.Sprintf("%.2f GiB", value)
} else {
value := float64(size) / float64(SIZE_TiB)
return fmt.Sprintf("%.2f TiB", value)
}
}