trying to fix error to remove element
This commit is contained in:
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user