dns: SortRegions() by ISO3166
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -34,6 +34,32 @@ func SortAddrRecords(s []AddrRecord) []AddrRecord {
|
||||
return s
|
||||
}
|
||||
|
||||
// SortRegions sorts regions. first by length those 3-character
|
||||
// or shorter, and then by length. It's mostly aimed at
|
||||
// supporting ISO-3166 order
|
||||
func SortRegions(regions []string) []string {
|
||||
sort.Slice(regions, func(i, j int) bool {
|
||||
r1, r2 := regions[i], regions[j]
|
||||
|
||||
switch {
|
||||
case len(r1) < 4:
|
||||
switch {
|
||||
case len(r1) < len(r2):
|
||||
return true
|
||||
case len(r1) > len(r2):
|
||||
return false
|
||||
default:
|
||||
return r1 < r2
|
||||
}
|
||||
case len(r2) < 4:
|
||||
return false
|
||||
default:
|
||||
return r1 < r2
|
||||
}
|
||||
})
|
||||
return regions
|
||||
}
|
||||
|
||||
// AddrRecord represents an A or AAAA record
|
||||
type AddrRecord struct {
|
||||
Name string
|
||||
|
||||
Reference in New Issue
Block a user