diff --git a/p2p/speedtest.go b/p2p/speedtest.go index a5e2674..43dc8c1 100644 --- a/p2p/speedtest.go +++ b/p2p/speedtest.go @@ -8,7 +8,7 @@ func (ip *IpAddresses)SpeedTest() error{ err := ip.IpAddress[i].PingTest() if err != nil { // Remove IP address of element not pingable - ip.IpAddress = append(ip.IpAddress[:i], ip.IpAddress[i+1:]...) + ip.IpAddress = remove(ip.IpAddress,i) // Proceed to next element in the array continue } @@ -86,3 +86,8 @@ func LocalSpeedTestIpTable() error { return nil } +// Helper function to remove element from an array of a struct +func remove(s []IpAddress, i int) []IpAddress { + s[len(s)-1], s[i] = s[i], s[len(s)-1] + return s[:len(s)-1] +}