Exemple #1
0
// Download config from speedtest.net
func GetConfig() Config {
	if debug.DEBUG {
		log.Printf("Getting config...\n")
	}
	resp, err := http.Get(SpeedtestConfigUrl)
	if err != nil {
		log.Panicf("Couldn't retrieve our config from speedtest.net: 'Could not create connection'\n")
	}
	defer resp.Body.Close()
	if checkHttp(resp) != true {
		log.Panicf("Couldn't retrieve our config from speedtest.net: '%s'\n", resp.Status)
	}

	body, err2 := ioutil.ReadAll(resp.Body)
	if err2 != nil {
		log.Panicf("Couldn't retrieve our config from speedtest.net: 'Cannot read body'\n")
	}

	cx := new(stxml.XMLConfigSettings)

	err3 := xml.Unmarshal(body, &cx)
	if err3 != nil {
		log.Panicf("Couldn't retrieve our config from speedtest.net: 'Cannot unmarshal XML'\n")
	}

	c := new(Config)
	c.Ip = cx.Client.Ip
	c.Lat = misc.ToFloat(cx.Client.Lat)
	c.Lon = misc.ToFloat(cx.Client.Lon)
	c.Isp = cx.Client.Isp

	return *c
}
Exemple #2
0
// Download config from speedtest.net
func GetConfig() Config {
	if debug.DEBUG {
		log.Printf("Getting config...\n")
	}
	resp, err := http.Get(SpeedtestConfigUrl)
	misc.E(err)
	defer resp.Body.Close()
	if checkHttp(resp) != true {
		log.Panicf("Fail: %s\n", resp.Status)
	}

	body, err2 := ioutil.ReadAll(resp.Body)
	misc.E(err2)

	cx := new(stxml.XMLConfigSettings)

	err3 := xml.Unmarshal(body, &cx)
	misc.E(err3)

	c := new(Config)
	c.Ip = cx.Client.Ip
	c.Lat = misc.ToFloat(cx.Client.Lat)
	c.Lon = misc.ToFloat(cx.Client.Lon)
	c.Isp = cx.Client.Isp

	return *c
}
Exemple #3
0
// Download server list from speedtest.net
func GetServers() []Server {
	var servers []Server

	if debug.DEBUG {
		log.Printf("Getting servers...\n")
	}

	resp, err := http.Get(SpeedtestServersUrl)
	if err != nil {
		log.Panicf("Cannot get servers list from speedtest.net: 'Cannot contact server'\n")
	}
	defer resp.Body.Close()

	body, err2 := ioutil.ReadAll(resp.Body)
	if err2 != nil {
		log.Panicf("Cannot get servers list from speedtest.net: 'Cannot read body'\n")
	}

	s := new(stxml.ServerSettings)

	err3 := xml.Unmarshal(body, &s)
	if err3 != nil {
		log.Panicf("Cannot get servers list from speedtest.net: 'Cannot unmarshal XML'\n")
	}

	for xmlServer := range s.ServersContainer.XMLServers {
		server := new(Server)
		server.Url = s.ServersContainer.XMLServers[xmlServer].Url
		server.Lat = misc.ToFloat(s.ServersContainer.XMLServers[xmlServer].Lat)
		server.Lon = misc.ToFloat(s.ServersContainer.XMLServers[xmlServer].Lon)
		server.Name = s.ServersContainer.XMLServers[xmlServer].Name
		server.Country = s.ServersContainer.XMLServers[xmlServer].Country
		server.CC = s.ServersContainer.XMLServers[xmlServer].CC
		server.Sponsor = s.ServersContainer.XMLServers[xmlServer].Sponsor
		server.Id = s.ServersContainer.XMLServers[xmlServer].Id
		servers = append(servers, *server)
	}

	if debug.DEBUG {
		log.Printf("Found %d servers...\n", len(servers))
	}
	return servers
}
Exemple #4
0
// Download server list from speedtest.net
func GetServers() []Server {
	var servers []Server

	if debug.DEBUG {
		log.Printf("Getting servers...\n")
	}

	resp, err := http.Get(SpeedtestServersUrl)
	misc.E(err)
	defer resp.Body.Close()

	body, err2 := ioutil.ReadAll(resp.Body)
	misc.E(err2)

	s := new(stxml.ServerSettings)

	err3 := xml.Unmarshal(body, &s)
	misc.E(err3)

	for xmlServer := range s.ServersContainer.XMLServers {
		server := new(Server)
		server.Url = s.ServersContainer.XMLServers[xmlServer].Url
		server.Lat = misc.ToFloat(s.ServersContainer.XMLServers[xmlServer].Lat)
		server.Lon = misc.ToFloat(s.ServersContainer.XMLServers[xmlServer].Lon)
		server.Name = s.ServersContainer.XMLServers[xmlServer].Name
		server.Country = s.ServersContainer.XMLServers[xmlServer].Country
		server.CC = s.ServersContainer.XMLServers[xmlServer].CC
		server.Sponsor = s.ServersContainer.XMLServers[xmlServer].Sponsor
		server.Id = s.ServersContainer.XMLServers[xmlServer].Id
		servers = append(servers, *server)
	}

	if debug.DEBUG {
		log.Printf("Found %d servers...\n", len(servers))
	}
	return servers
}