(ips []string)
| 23 | ) |
| 24 | |
| 25 | func SortIpAddresses(ips []string) (orderedIps []string) { |
| 26 | realIPs := make([]net.IP, 0, len(ips)) |
| 27 | keys := make(map[string]bool) |
| 28 | |
| 29 | for _, ip := range ips { |
| 30 | // Avoid duplicated keys |
| 31 | if _, value := keys[ip]; !value { |
| 32 | keys[ip] = true |
| 33 | realIPs = append(realIPs, net.ParseIP(ip)) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | sort.Slice(realIPs, func(i, j int) bool { |
| 38 | return bytes.Compare(realIPs[i], realIPs[j]) < 0 |
| 39 | }) |
| 40 | |
| 41 | for _, ip := range realIPs { |
| 42 | orderedIps = append(orderedIps, ip.String()) |
| 43 | } |
| 44 | |
| 45 | return |
| 46 | } |
no test coverage detected