-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
74 lines (66 loc) · 1.17 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
71
72
73
74
package extract
import (
"strconv"
"strings"
)
func GetSite(url string) string {
scheme := "http://"
i := strings.Index(url, scheme);
if i != -1 {
url = url[len(scheme):]
}
i = strings.Index(url, "/")
if i != -1 {
url = url[0:i]
}
return url
}
func GetDomain(url string) string {
scheme := "http://"
i := strings.Index(url, scheme);
if i != -1 {
url = url[len(scheme):]
}
i = strings.Index(url, "/")
if i != -1 {
url = url[0:i]
}
i = strings.LastIndex(url, ".")
if i == -1 {
return url
}
seg := url[0:i]
i = strings.LastIndex(seg, ".")
if i == -1 {
return url
}
domain := url[i+1:]
return domain
}
func MapAddArrayPanic(m map[string]string, a []string) {
for i, s := range(a) {
index := strconv.Itoa(i)
_, ok := m[index]
if ok {
panic("[MapAddArray] " + index + " already exist in map")
}
m[index] = s
}
}
func MapAddArrayCover(m map[string]string, a []string) {
for i, s := range(a) {
index := strconv.Itoa(i)
_, ok := m[index]
if ok {
delete(m, index)
}
m[index] = s
}
}
func MapAddArrayDiscard(m map[string]string, a []string) {
for i, s := range(a) {
if _, ok := m[s]; !ok {
m[strconv.Itoa(i)] = s
}
}
}