-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
64 lines (51 loc) · 956 Bytes
/
utils.go
File metadata and controls
64 lines (51 loc) · 956 Bytes
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
60
61
62
63
64
package packer
import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
)
func isDir(path string) (bool, error) {
stat, err := os.Stat(path)
if err != nil {
return false, err
}
return stat.IsDir(), nil
}
func getFilesFromPath(path string) (s []string, err error) {
isDir, err := isDir(path)
if err != nil {
return nil, err
}
if !isDir {
return []string{path}, nil
}
return s, filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
s = append(s, path)
return nil
})
}
func readFileContent(f string) (string, error) {
b, err := ioutil.ReadFile(f)
return string(b), err
}
func hashFileName(s string) string {
return strings.ReplaceAll(s, "[hash]", fmt.Sprint(time.Now().UnixNano()))
}
func sliceContains(s []string, v string) bool {
for _, x := range s {
if v == x {
return true
}
}
return false
}