-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
65 lines (48 loc) · 1.05 KB
/
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
59
60
61
62
63
64
65
package fox
import (
"errors"
"regexp"
"time"
)
func formatTime(t int) string {
return time.Now().Add(time.Millisecond * time.Duration(t)).Format("Mon, 02 Jan 2006 15:04:05 GMT")
}
func formatWithDelimiter(arr []string, delimiter string, ignore string) string {
if len(arr) == 0 {
return ""
}
formatted := ""
for i := 1; i < len(arr); i++ {
if arr[i] == ignore {
continue
}
formatted += delimiter + arr[i]
}
return arr[0] + formatted
}
// split access control request
func splitComma(target string) map[string]bool {
rex := regexp.MustCompile(`\s+,\s+|\s+,|,\s+|,`)
arr := rex.Split(target, -1)
mappedTarget := map[string]bool{}
for _, a := range arr {
mappedTarget[a] = true
}
return mappedTarget
}
func Ext(path string) (string, error) {
for i := len(path) - 1; i >= 0; i-- {
if path[i] == '.' {
return path[i+1:], nil
}
}
return "", errors.New("no extension")
}
func Dir(path string) string {
for i := len(path) - 1; i >= 0; i-- {
if path[i] == '/' || path[i] == '\\' {
return path[:i]
}
}
return path
}