speedtest

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 14 Imported by: 74

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Locations = map[string]Location{
	"brasilia":     {"br", -15.793876, -47.8835327},
	"hongkong":     {"hk", 22.3106806, 114.1700546},
	"tokyo":        {"jp", 35.680938, 139.7674114},
	"london":       {"uk", 51.5072493, -0.1288861},
	"moscow":       {"ru", 55.7497248, 37.615989},
	"beijing":      {"cn", 39.8721243, 116.4077473},
	"paris":        {"fr", 48.8626026, 2.3477229},
	"sanfrancisco": {"us", 37.7540028, -122.4429967},
	"newyork":      {"us", 40.7200876, -74.0220945},
	"yishun":       {"sg", 1.4230218, 103.8404728},
	"delhi":        {"in", 28.6251287, 77.1960896},
	"monterrey":    {"mx", 25.6881435, -100.3073485},
	"berlin":       {"de", 52.5168128, 13.4009469},
	"maputo":       {"mz", -25.9579267, 32.5760444},
	"honolulu":     {"us", 20.8247065, -156.918706},
	"seoul":        {"kr", 37.6086268, 126.7179721},
	"osaka":        {"jp", 34.6952743, 135.5006967},
	"shanghai":     {"cn", 31.2292105, 121.4661666},
	"urumqi":       {"cn", 43.8256624, 87.6058564},
	"ottawa":       {"ca", 45.4161836, -75.7035467},
	"capetown":     {"za", -33.9391993, 18.4316716},
	"sydney":       {"au", -33.8966622, 151.1731861},
	"perth":        {"au", -31.9551812, 115.8591904},
	"warsaw":       {"pl", 52.2396659, 21.0129345},
	"kampala":      {"ug", 0.3070027, 32.5675581},
	"bangkok":      {"th", 13.7248936, 100.493026},
}

Locations TODO more location need to added

Functions

func PrintCityList added in v1.2.0

func PrintCityList()

func Version added in v1.3.0

func Version() string

Types

type ByDistance

type ByDistance struct {
	Servers
}

ByDistance for sorting servers.

func (ByDistance) Less

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

Less compares the distance. For sorting servers.

type Location added in v1.2.0

type Location struct {
	CC  string
	Lat float64
	Lon float64
}

type Option added in v1.1.5

type Option func(*Speedtest)

Option is a function that can be passed to New to modify the Client.

func WithDoer added in v1.1.5

func WithDoer(doer *http.Client) Option

WithDoer sets the http.Client used to make requests.

func WithUserAgent added in v1.3.0

func WithUserAgent(UserAgent string) Option

WithUserAgent adds the passed "User-Agent" header to all requests. To use with a custom Doer, "WithDoer" must be passed before WithUserAgent: `New(WithDoer(myDoer), WithUserAgent(myUserAgent))`

type PayloadType added in v1.1.5

type PayloadType int
const (
	JSONPayload PayloadType = iota
	XMLPayload
)

type Server

type Server struct {
	URL      string        `xml:"url,attr" json:"url"`
	Lat      string        `xml:"lat,attr" json:"lat"`
	Lon      string        `xml:"lon,attr" json:"lon"`
	Name     string        `xml:"name,attr" json:"name"`
	Country  string        `xml:"country,attr" json:"country"`
	Sponsor  string        `xml:"sponsor,attr" json:"sponsor"`
	ID       string        `xml:"id,attr" json:"id"`
	URL2     string        `xml:"url2,attr" json:"url_2"`
	Host     string        `xml:"host,attr" json:"host"`
	Distance float64       `json:"distance"`
	Latency  time.Duration `json:"latency"`
	DLSpeed  float64       `json:"dl_speed"`
	ULSpeed  float64       `json:"ul_speed"`
	// contains filtered or unexported fields
}

Server information

func (Server) CheckResultValid

func (s Server) CheckResultValid() bool

CheckResultValid checks that results are logical given UL and DL speeds

func (*Server) DownloadTest

func (s *Server) DownloadTest(savingMode bool) error

DownloadTest executes the test to measure download speed

func (*Server) DownloadTestContext added in v1.1.3

func (s *Server) DownloadTestContext(ctx context.Context, savingMode bool) error

DownloadTestContext executes the test to measure download speed, observing the given context.

func (*Server) PingTest

func (s *Server) PingTest() error

PingTest executes test to measure latency

func (*Server) PingTestContext added in v1.1.3

func (s *Server) PingTestContext(ctx context.Context) error

PingTestContext executes test to measure latency, observing the given context.

func (*Server) String

func (s *Server) String() string

String representation of Server

func (*Server) UploadTest

func (s *Server) UploadTest(savingMode bool) error

UploadTest executes the test to measure upload speed

func (*Server) UploadTestContext added in v1.1.3

func (s *Server) UploadTestContext(ctx context.Context, savingMode bool) error

UploadTestContext executes the test to measure upload speed, observing the given context.

type ServerList

type ServerList struct {
	Servers []*Server `xml:"servers>server"`
}

ServerList list of Server

func (ServerList) String

func (l ServerList) String() string

String representation of ServerList

type Servers

type Servers []*Server

Servers for sorting servers.

func FetchServerListContext added in v1.1.3

func FetchServerListContext(ctx context.Context, user *User) (Servers, error)

FetchServerListContext retrieves a list of available servers, observing the given context.

func FetchServers added in v1.1.5

func FetchServers(user *User) (Servers, error)

FetchServers retrieves a list of available servers

func (Servers) FindServer added in v1.1.5

func (l Servers) FindServer(serverID []int) (Servers, error)

FindServer finds server by serverID

func (Servers) Len

func (svrs Servers) Len() int

Len finds length of servers. For sorting servers.

func (Servers) String added in v1.1.5

func (l Servers) String() string

String representation of Servers

func (Servers) Swap

func (svrs Servers) Swap(i, j int)

Swap swaps i-th and j-th. For sorting servers.

type Speedtest added in v1.1.5

type Speedtest struct {
	// contains filtered or unexported fields
}

Speedtest is a speedtest client.

func New added in v1.1.5

func New(opts ...Option) *Speedtest

New creates a new speedtest client.

func (*Speedtest) FetchServerListContext added in v1.1.5

func (client *Speedtest) FetchServerListContext(ctx context.Context, user *User) (Servers, error)

FetchServerListContext retrieves a list of available servers, observing the given context.

func (*Speedtest) FetchServers added in v1.1.5

func (client *Speedtest) FetchServers(user *User) (Servers, error)

FetchServers retrieves a list of available servers

func (*Speedtest) FetchUserInfo added in v1.1.5

func (client *Speedtest) FetchUserInfo() (*User, error)

FetchUserInfo returns information about caller determined by speedtest.net

func (*Speedtest) FetchUserInfoContext added in v1.1.5

func (client *Speedtest) FetchUserInfoContext(ctx context.Context) (*User, error)

FetchUserInfoContext returns information about caller determined by speedtest.net, observing the given context.

type User

type User struct {
	IP   string `xml:"ip,attr"`
	Lat  string `xml:"lat,attr"`
	Lon  string `xml:"lon,attr"`
	Isp  string `xml:"isp,attr"`
	VLoc string `xml:"v_loc,attr"` // virtual location name
	VLat string `xml:"v_lat,attr"` // virtual lat
	VLon string `xml:"v_lon,attr"` // virtual lon
}

User represents information determined about the caller by speedtest.net

func FetchUserInfo

func FetchUserInfo() (*User, error)

FetchUserInfo returns information about caller determined by speedtest.net

func FetchUserInfoContext added in v1.1.3

func FetchUserInfoContext(ctx context.Context) (*User, error)

FetchUserInfoContext returns information about caller determined by speedtest.net, observing the given context.

func (*User) ParseAndSetLocation added in v1.2.0

func (u *User) ParseAndSetLocation(coordinateStr string) error

ParseAndSetLocation parse latitude and longitude string

func (*User) SetLocation added in v1.2.0

func (u *User) SetLocation(locationName string, latitude float64, longitude float64)

SetLocation set the latitude and longitude of the current user

func (*User) SetLocationByCity added in v1.2.0

func (u *User) SetLocationByCity(locationLabel string) (err error)

SetLocationByCity set current location using predefined location label.

func (*User) String

func (u *User) String() string

String representation of User

type Users

type Users struct {
	Users []User `xml:"client"`
}

Users for decode xml

Jump to

Keyboard shortcuts

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