added fix for removing elements from the array

This commit is contained in:
2021-05-24 13:58:24 +04:00
parent 65e633e6c4
commit f89e7ccbcb
4 changed files with 12 additions and 17 deletions

1
go.mod
View File

@@ -29,6 +29,7 @@ require (
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/tools v0.0.0-20210106214847-113979e3529a
google.golang.org/grpc v1.35.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools/v3 v3.0.3 // indirect

1
go.sum
View File

@@ -820,6 +820,7 @@ golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapK
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@@ -1,16 +1,3 @@
{
"ip_address": [
{
"ipv4": "147.75.100.225",
"latency": 1582411,
"download": 279180.07603469375,
"upload": 855366.1394760027
},
{
"ipv4": "86.99.70.106",
"latency": 134446840,
"download": 1582.176490711659,
"upload": 597823.3252726822
}
]
"ip_address": null
}

View File

@@ -8,9 +8,9 @@ func (ip *IpAddresses)SpeedTest() error{
for i, value := range ip.IpAddress {
var err error
if len(ip.IpAddress) == 1 {
i = 0
}
//if len(ip.IpAddress) == 1 {
// i = 0
//}
// Ping Test
err = value.PingTest()
@@ -40,6 +40,12 @@ func (ip *IpAddresses)SpeedTest() error{
}
// Remove element from struct
for _, index := range RemoveIndex {
// If there is only 1 element and that has to be
// removed
if len(ip.IpAddress) == 1 {
ip.IpAddress = nil
break
}
ip.IpAddress = append(ip.IpAddress[:index], ip.IpAddress[index+1:]...)
}