25 lines
417 B
Go
25 lines
417 B
Go
|
|
package updater
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bytes"
|
||
|
|
"net"
|
||
|
|
"sort"
|
||
|
|
)
|
||
|
|
|
||
|
|
func uniqueSortedIPs(ips []net.IP) []net.IP {
|
||
|
|
uniqueIPs := make(map[string]struct{})
|
||
|
|
for _, ip := range ips {
|
||
|
|
uniqueIPs[ip.String()] = struct{}{}
|
||
|
|
}
|
||
|
|
ips = make([]net.IP, len(uniqueIPs))
|
||
|
|
i := 0
|
||
|
|
for ip := range uniqueIPs {
|
||
|
|
ips[i] = net.ParseIP(ip)
|
||
|
|
i++
|
||
|
|
}
|
||
|
|
sort.Slice(ips, func(i, j int) bool {
|
||
|
|
return bytes.Compare(ips[i], ips[j]) < 0
|
||
|
|
})
|
||
|
|
return ips
|
||
|
|
}
|