-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefixRanger.go
44 lines (40 loc) · 942 Bytes
/
prefixRanger.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
package main
import (
"fmt"
"os"
"sort"
"strconv"
"strings"
)
func generatePrefixList(aspaths []string) {
var prefixLists []string
for _, v := range aspaths {
if strings.Contains(v, "-") {
rangeSplit := strings.Split(v, "-")
start, err := strconv.Atoi(rangeSplit[0])
if err != nil {
panic(err)
}
end, err := strconv.Atoi(rangeSplit[1])
if err != nil {
panic(err)
}
if start == end {
prefixLists = append(prefixLists, fmt.Sprintf(*fmtAsPathFmt, *fmtASPathNameFmt,
"_"+strconv.Itoa(start)))
} else {
prefixLists = append(prefixLists, fmt.Sprintf(*fmtAsPathFmt, *fmtASPathNameFmt,
GetRegex(start, end)))
}
} else {
prefixLists = append(prefixLists, fmt.Sprintf(*fmtAsPathFmt, *fmtASPathNameFmt, "_"+v))
}
}
sort.Slice(prefixLists,
func(i, j int) bool {
return prefixLists[i] < prefixLists[j]
})
for _, v := range prefixLists {
fmt.Fprint(os.Stdout, v)
}
}