Skip to content

Commit

Permalink
Change from http.DefaultClient to
Browse files Browse the repository at this point in the history
http.Client
  • Loading branch information
Sébastien B authored and Sébastien B committed Dec 4, 2019
1 parent 4d9219a commit c5a12b9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"strings"
Expand All @@ -13,7 +12,6 @@ import (

var dlSizes = [...]int{350, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000}
var ulSizes = [...]int{100, 300, 500, 800, 1000, 1500, 2500, 3000, 3500, 4000} //kB
var client = http.Client{}

func downloadTest(sURL string, latency time.Duration) float64 {
dlURL := strings.Split(sURL, "/upload")[0]
Expand Down Expand Up @@ -177,7 +175,7 @@ func pingTest(sURL string) time.Duration {
l := time.Duration(100000000000) // 10sec
for i := 0; i < 3; i++ {
sTime := time.Now()
resp, err := http.Get(pingURL)
resp, err := client.Get(pingURL)
fTime := time.Now()
checkError(err)
defer resp.Body.Close()
Expand Down
5 changes: 2 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io/ioutil"
"math"
"net/http"
"sort"
"strconv"
)
Expand Down Expand Up @@ -57,14 +56,14 @@ func (b ByDistance) Less(i, j int) bool {

func fetchServerList(user User) ServerList {
// Fetch xml server data
resp, err := http.Get("http://www.speedtest.net/speedtest-servers-static.php")
resp, err := client.Get("http://www.speedtest.net/speedtest-servers-static.php")
checkError(err)
body, err := ioutil.ReadAll(resp.Body)
checkError(err)
defer resp.Body.Close()

if len(body) == 0 {
resp, err = http.Get("http://c.speedtest.net/speedtest-servers-static.php")
resp, err = client.Get("http://c.speedtest.net/speedtest-servers-static.php")
checkError(err)
body, err = ioutil.ReadAll(resp.Body)
checkError(err)
Expand Down
2 changes: 2 additions & 0 deletions speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

var client = http.Client{}

func checkError(err error) {
if err != nil {
log.Fatal(err)
Expand Down
3 changes: 1 addition & 2 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
)

// User information
Expand All @@ -23,7 +22,7 @@ type Users struct {

func fetchUserInfo() User {
// Fetch xml user data
resp, err := http.Get("http://speedtest.net/speedtest-config.php")
resp, err := client.Get("http://speedtest.net/speedtest-config.php")
checkError(err)
body, err := ioutil.ReadAll(resp.Body)
checkError(err)
Expand Down

0 comments on commit c5a12b9

Please sign in to comment.