Skip to content

Commit

Permalink
Adds speedtest package to enable use of api
Browse files Browse the repository at this point in the history
  • Loading branch information
cbergoon authored and showwin committed Nov 26, 2020
1 parent 8e983a5 commit 9f3fd47
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
14 changes: 3 additions & 11 deletions speedtest.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package main

import (
"log"
"os"

"gopkg.in/alecthomas/kingpin.v2"
"github.com/cbergoon/speedtest-go/speedtest"
)

func checkError(err error) {
if err != nil {
log.Fatal(err)
os.Exit(1)
}
}

func setTimeout() {
if *timeoutOpt != 0 {
Expand All @@ -33,10 +25,10 @@ func main() {

setTimeout()

user := fetchUserInfo()
user := speedtest.FetchUserInfo()
user.Show()

list := fetchServerList(user)
list := speedtest.FetchServerList(user)
if *showList {
list.Show()
return
Expand Down
2 changes: 1 addition & 1 deletion request.go → speedtest/request.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package speedtest

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions server.go → speedtest/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package speedtest

import (
"bytes"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (b ByDistance) Less(i, j int) bool {
return b.Servers[i].Distance < b.Servers[j].Distance
}

func fetchServerList(user User) ServerList {
func FetchServerList(user User) ServerList {
// Fetch xml server data
resp, err := http.Get("http://www.speedtest.net/speedtest-servers-static.php")
checkError(err)
Expand Down
4 changes: 2 additions & 2 deletions user.go → speedtest/user.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package speedtest

import (
"bytes"
Expand All @@ -21,7 +21,7 @@ type Users struct {
Users []User `xml:"client"`
}

func fetchUserInfo() User {
func FetchUserInfo() User {
// Fetch xml user data
resp, err := http.Get("http://speedtest.net/speedtest-config.php")
checkError(err)
Expand Down
13 changes: 13 additions & 0 deletions speedtest/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package speedtest

import (
"log"
"os"
)

func checkError(err error) {
if err != nil {
log.Fatal(err)
os.Exit(1)
}
}

0 comments on commit 9f3fd47

Please sign in to comment.