trying to fix error to remove element

This commit is contained in:
2021-04-14 22:10:02 +04:00
parent 977260dcf7
commit 1093f34ce8

View File

@@ -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]
}