sthttp

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2018 License: GPL-2.0, GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByDistance

type ByDistance []Server

ByDistance allows us to sort servers by distance

func (ByDistance) Len

func (server ByDistance) Len() int

func (ByDistance) Less

func (server ByDistance) Less(i, j int) bool

func (ByDistance) Swap

func (server ByDistance) Swap(i, j int)

type ByLatency

type ByLatency []Server

ByLatency allows us to sort servers by latency

func (ByLatency) Len

func (server ByLatency) Len() int

func (ByLatency) Less

func (server ByLatency) Less(i, j int) bool

func (ByLatency) Swap

func (server ByLatency) Swap(i, j int)

type Client added in v1.0.4

type Client struct {
	Config          *Config
	SpeedtestConfig *SpeedtestConfig
	HTTPConfig      *HTTPConfig
	Debug           bool
	ReportChar      string
}

Client define a Speedtest HTTP client

func NewClient added in v1.0.4

func NewClient(speedtestConfig *SpeedtestConfig, httpConfig *HTTPConfig, debug bool, reportChar string) *Client

NewClient define a new Speedtest client.

func (*Client) DownloadSpeed added in v1.0.4

func (stClient *Client) DownloadSpeed(url string) (speed float64, err error)

DownloadSpeed measures the mbps of downloading a URL

func (*Client) GetClosestServers added in v1.0.4

func (stClient *Client) GetClosestServers(servers []Server) []Server

GetClosestServers takes the full server list and sorts by distance

func (*Client) GetConfig added in v1.0.4

func (stClient *Client) GetConfig() (c Config, err error)

GetConfig downloads the master config from speedtest.net

func (*Client) GetFastestServer added in v1.0.4

func (stClient *Client) GetFastestServer(servers []Server) Server

GetFastestServer test all servers until we find numServers that respond, then find the fastest of them. Some servers show up in the master list but timeout or are "corrupt" therefore we bump their latency to something really high (1 minute) and they will drop out of this test

func (*Client) GetLatency added in v1.0.4

func (stClient *Client) GetLatency(server Server, url string) (result float64, err error)

GetLatency will test the latency (ping) the given server NUMLATENCYTESTS times and return either the lowest or average depending on what algorithm is set

func (*Client) GetLatencyURL added in v1.0.4

func (stClient *Client) GetLatencyURL(server Server) string

GetLatencyURL will return the proper url for the latency

func (*Client) GetServers added in v1.0.4

func (stClient *Client) GetServers() (servers []Server, err error)

GetServers will get the full server list

func (*Client) UploadSpeed added in v1.0.4

func (stClient *Client) UploadSpeed(url string, mimetype string, data []byte) (speed float64, err error)

UploadSpeed measures the mbps to http.Post to a URL

type Config

type Config struct {
	IP  string
	Lat float64
	Lon float64
	Isp string
}

Config struct holds our config (users current ip, lat, lon and isp)

type HTTPConfig added in v1.0.4

type HTTPConfig struct {
	HTTPTimeout time.Duration
}

HTTPConfig define settings for HTTP requests

type Server

type Server struct {
	URL      string
	Lat      float64
	Lon      float64
	Name     string
	Country  string
	CC       string
	Sponsor  string
	ID       string
	Distance float64
	Latency  float64
}

Server struct is a speedtest candidate server

type SpeedtestConfig added in v1.0.4

type SpeedtestConfig struct {
	ConfigURL       string
	ServersURL      string
	AlgoType        string
	NumClosest      int
	NumLatencyTests int
	Interface       string
	Blacklist       []string
	UserAgent       string
}

SpeedtestConfig define Speedtest settings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL