From 1093f34ce8ac7f343615afb2170bada66fd0d70c Mon Sep 17 00:00:00 2001 From: Akilan Date: Wed, 14 Apr 2021 22:10:02 +0400 Subject: [PATCH] trying to fix error to remove element --- p2p/speedtest.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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] +}