Skip to content

Commit

Permalink
fix: specify servers with new api (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
r3inbowari authored Sep 4, 2023
1 parent cdb3343 commit df44d44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strconv"
"time"

"github.com/showwin/speedtest-go/speedtest"
Expand Down Expand Up @@ -78,6 +79,17 @@ func main() {
task.CheckError(err)
targets = []*speedtest.Server{target}
task.Println("Skip: Using Custom Server")
} else if len(*serverIds) > 0 {
// TODO: need async fetch to speedup
for _, id := range *serverIds {
serverPtr, errFetch := speedtestClient.FetchServerByID(strconv.Itoa(id))
if errFetch != nil {
continue // Silently Skip all ids that actually don't exist.
}
targets = append(targets, serverPtr)
}
task.CheckError(err)
task.Printf("Found %d Specified Public Servers", len(targets))
} else {
servers, err = speedtestClient.FetchServers()
task.CheckError(err)
Expand Down
1 change: 1 addition & 0 deletions speedtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func (servers Servers) FindServer(serverID []int) (Servers, error) {
id, _ := strconv.Atoi(s.ID)
if sid == id {
retServer = append(retServer, s)
break
}
}
}
Expand Down

0 comments on commit df44d44

Please sign in to comment.