-
Notifications
You must be signed in to change notification settings - Fork 55
/
aliases.go
58 lines (45 loc) · 980 Bytes
/
aliases.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 serverHandler
import (
"sort"
)
type aliases []alias
func newAliases(entries [][2]string) aliases {
aliases := make(aliases, 0, len(entries))
for i := range entries {
aliases = append(aliases, createAlias(entries[i][0], entries[i][1]))
}
sort.Sort(aliases)
return aliases
}
func (list aliases) byUrlPath(urlPath string) (aliasItem alias, ok bool) {
for _, alias := range list {
if alias.isMatch(urlPath) {
return alias, true
}
}
return alias{}, false
}
func (list aliases) filterSuccessor(url string) aliases {
var result aliases
for _, a := range list {
if a.isSuccessorOf(url) {
result = append(result, a)
}
}
return result
}
func (list aliases) Len() int {
return len(list)
}
func (list aliases) Less(i, j int) bool {
iLen := len(list[i].url)
jLen := len(list[j].url)
if iLen != jLen {
// longer is prior
return iLen > jLen
}
return i > j
}
func (list aliases) Swap(i, j int) {
list[i], list[j] = list[j], list[i]
}