-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
58 lines (50 loc) · 1013 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
51
52
53
54
55
56
57
58
package gim
import (
"math/rand"
"os"
"path"
"path/filepath"
"strings"
)
const alphabet = "abcdefghijklmnopqrst0123456789"
func (g *Gim) cutPath(father string, value string) string {
cutestPath := strings.Replace(value, father, "", 1)
return path.Join(".", cutestPath)
}
func (g *Gim) normalize(routes routesTree) routesTree {
vRoutes := make(routesTree)
for k, r := range routes {
if len(r) != 0 {
norm := g.normalize(r)
vRoutes[k] = norm
} else {
vRoutes[k] = routesTree{}
}
}
return vRoutes
}
func (g *Gim) generateLittleHash(size int) string {
hash := ""
for i := 0; i < size; i++ {
hash += string(alphabet[rand.Intn(len(alphabet))])
}
return hash
}
func (g *Gim) removeContents(dir string) error {
d, err := os.Open(dir)
if err != nil {
return err
}
defer d.Close()
names, err := d.Readdirnames(-1)
if err != nil {
return err
}
for _, name := range names {
err = os.RemoveAll(filepath.Join(dir, name))
if err != nil {
return err
}
}
return nil
}