-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
66 lines (50 loc) · 941 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
59
60
61
62
63
64
65
66
package hedrs
import "strings"
func valuesToString(vs []string) string {
return strings.Join(vs, ", ")
}
func applyAndAddToMap(m map[string]struct{}, fn func(string) string, keys ...string) {
if fn == nil {
fn = passThrough
}
for _, v := range keys {
v = fn(v)
if v == "" {
continue
}
m[v] = struct{}{}
}
}
func applyAndDeleteFromMap(m map[string]struct{}, fn func(string) string, keys ...string) {
if fn == nil {
fn = passThrough
}
for _, v := range keys {
v = fn(v)
if v == "" {
continue
}
delete(m, v)
}
}
func hasKeyOrWildcard(m map[string]struct{}, key string) bool {
_, ok := m[key]
if ok {
return true
}
_, ok = m["*"]
return ok
}
func passThrough(s string) string {
return s
}
func prunePort(host string) string {
for k := range host {
i := len(host) - k - 1
v := host[i]
if v == ':' && len(host) >= i+2 && host[i+1] != '/' {
return host[:i]
}
}
return host
}