-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.go
70 lines (60 loc) · 1.2 KB
/
util.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
66
67
68
69
70
package main
import (
"net"
"strings"
"github.com/google/uuid"
)
func CreateBranch() (string, error) {
uuid, err := uuid.NewRandom()
if err == nil {
tmp := strings.Split(uuid.String(), "-")
return "z9hG4bK" + tmp[len(tmp)-1], nil
}
return "", err
}
func CreateTag() (string, error) {
uuid, err := uuid.NewRandom()
if err == nil {
tmp := strings.Split(uuid.String(), "-")
return tmp[len(tmp)-1], nil
}
return "", err
}
func inStrArray(s string, a []string) bool {
for _, t := range a {
if t == s {
return true
}
}
return false
}
func strArraySub(a1 []string, a2 []string) []string {
r := make([]string, 0)
for _, s := range a1 {
if !inStrArray(s, a2) {
r = append(r, s)
}
}
return r
}
/*
func splitAddr(addr string) (hostname string, port string, err error) {
pos := strings.LastIndex(addr, ":")
if pos == -1 {
err = errors.New("not a valid address")
} else {
hostname = addr[0:pos]
port = addr[pos+1:]
err = nil
}
return
}*/
func isIPAddress(addr string) bool {
if strings.HasPrefix(addr, "[") && strings.HasSuffix(addr, "]") {
addr = addr[1 : len(addr)-1]
}
return net.ParseIP(addr) != nil
}
func isIPv6(ip string) bool {
return strings.Contains(ip, ":")
}