utils/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
51
52
53
54
55
56
package utils import ( "crypto/sha256" "fmt" "io" "os" ) var ZoaRoot string func SetZoaRoot(root string) { ZoaRoot = root } // Copy just copiez files, it's only used by zoaCopy rn func Copy(src, dst string) error { in, err := os.Open(src) if err != nil { return err } defer in.Close() out, err := os.Create(dst) if err != nil { return err } defer out.Close() _, err = io.Copy(out, in) if err != nil { return err } return out.Close() } func ChecksumFile(file string) (string, error) { f, err := os.Open(file) if err != nil { return "", err } defer f.Close() h := sha256.New() if _, err := io.Copy(h, f); err != nil { return "", err } checksum := fmt.Sprintf("%x", h.Sum(nil)) return checksum, nil } func BluePrintln(s string) { colored := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 34, s) fmt.Println(colored) }