Skip to content

Commit 6199090

Browse files
committed
Use ID from server JSON instead of slice index
1 parent 166771b commit 6199090

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ locally via `--local-json`). The format is as below:
170170
```json
171171
[
172172
{
173+
"id": 1,
173174
"name": "PHP Backend",
174175
"server": "https://example.com/",
175176
"dlURL": "garbage.php",
@@ -178,6 +179,7 @@ locally via `--local-json`). The format is as below:
178179
"getIpURL": "getIP.php"
179180
},
180181
{
182+
"id": 2,
181183
"name": "Go Backend",
182184
"server": "http://example.com/speedtest/",
183185
"dlURL": "garbage",

defs/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
// Server represents a speed test server
2424
type Server struct {
25+
ID int `json:"id"`
2526
Name string `json:"name"`
2627
Server string `json:"server"`
2728
DownloadURL string `json:"dlURL"`

speedtest/speedtest.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func SpeedTest(c *cli.Context) error {
224224
if str := c.String(defs.OptionServerJSON); str != "" {
225225
serverUrl = str
226226
}
227-
log.Info("Retrieving server list from %s", serverUrl)
227+
log.Infof("Retrieving server list from %s", serverUrl)
228228

229229
servers, err = getServerList(c.Bool(defs.OptionSecure), serverUrl, c.IntSlice(defs.OptionExclude), c.IntSlice(defs.OptionServer), !c.Bool(defs.OptionList))
230230

@@ -240,12 +240,12 @@ func SpeedTest(c *cli.Context) error {
240240

241241
// if --list is given, list all the servers fetched and exit
242242
if c.Bool(defs.OptionList) {
243-
for idx, svr := range servers {
243+
for _, svr := range servers {
244244
var sponsorMsg string
245245
if svr.Sponsor() != "" {
246246
sponsorMsg = fmt.Sprintf(" [Sponsor: %s]", svr.Sponsor())
247247
}
248-
log.Warnf("%d: %s (%s) %s", idx, svr.Name, svr.Server, sponsorMsg)
248+
log.Warnf("%d: %s (%s) %s", svr.ID, svr.Name, svr.Server, sponsorMsg)
249249
}
250250
return nil
251251
}
@@ -415,8 +415,8 @@ func preprocessServers(servers []defs.Server, forceHTTPS bool, excludes, specifi
415415
// exclude servers from --exclude
416416
if len(excludes) > 0 {
417417
var ret []defs.Server
418-
for idx, server := range servers {
419-
if contains(excludes, idx) {
418+
for _, server := range servers {
419+
if contains(excludes, server.ID) {
420420
continue
421421
}
422422
ret = append(ret, server)
@@ -428,8 +428,8 @@ func preprocessServers(servers []defs.Server, forceHTTPS bool, excludes, specifi
428428
// special value -1 will test all servers
429429
if len(specific) > 0 && !contains(specific, -1) {
430430
var ret []defs.Server
431-
for idx, server := range servers {
432-
if contains(specific, idx) {
431+
for _, server := range servers {
432+
if contains(specific, server.ID) {
433433
ret = append(ret, server)
434434
}
435435
}

0 commit comments

Comments
 (0)