speedtest

package
v0.0.0-...-3c3e16a Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultErrorLatency = time.Hour
View Source
const DefaultLatencyMeasureTimes = 4
View Source
const Version = "1.0.0"

Variables

View Source
var NoServersError error = errors.New("No servers available")

Functions

This section is empty.

Types

type Client

type Client interface {
	Log(format string, a ...interface{})
	Config() (*Config, error)
	LoadConfig(ret chan ConfigRef)
	NewRequest(method string, url string, body io.Reader) (*http.Request, error)
	Get(url string) (resp *Response, err error)
	Post(url string, bodyType string, body io.Reader) (resp *Response, err error)
	AllServers() (*Servers, error)
	LoadAllServers(ret chan ServersRef)
	ClosestServers() (*Servers, error)
	LoadClosestServers(ret chan ServersRef)
}

func NewClient

func NewClient(opts *Opts) Client

type ClientConfig

type ClientConfig struct {
	Coordinates
	IP                 string  `xml:"ip,attr"`
	ISP                string  `xml:"isp,attr"`
	ISPRating          float32 `xml:"isprating,attr"`
	ISPDownloadAverage uint32  `xml:"ispdlavg,attr"`
	ISPUploadAverage   uint32  `xml:"ispulavg,attr"`
	Rating             float32 `xml:"rating,attr"`
	LoggedIn           uint8   `xml:"loggedin,attr"`
}

type Config

type Config struct {
	Client ClientConfig `xml:"client"`
	Times  ConfigTimes  `xml:"times"`
}

type ConfigRef

type ConfigRef struct {
	Config *Config
	Error  error
}

type ConfigTime

type ConfigTime struct {
	Upload   uint32
	Download uint32
}

type ConfigTimes

type ConfigTimes []ConfigTime

func (ConfigTimes) UnmarshalXML

func (times ConfigTimes) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Coordinates

type Coordinates struct {
	Latitude  float32 `xml:"lat,attr"`
	Longitude float32 `xml:"lon,attr"`
}

func (Coordinates) DistanceTo

func (org Coordinates) DistanceTo(dest Coordinates) float64

type Opts

type Opts struct {
	SpeedInBytes bool
	Quiet        bool
	List         bool
	Server       ServerID
	Interface    string
	Timeout      time.Duration
	Secure       bool
	Help         bool
	Version      bool
}

func ParseOpts

func ParseOpts() *Opts

type Response

type Response http.Response

func (*Response) ReadContent

func (resp *Response) ReadContent() ([]byte, error)

func (*Response) ReadXML

func (resp *Response) ReadXML(out interface{}) error

type Server

type Server struct {
	Coordinates
	URL     string   `xml:"url,attr"`
	Name    string   `xml:"name,attr"`
	Country string   `xml:"country,attr"`
	CC      string   `xml:"cc,attr"`
	Sponsor string   `xml:"sponsor,attr"`
	ID      ServerID `xml:"id,attr"`
	URL2    string   `xml:"url2,attr"`
	Host    string   `xml:"host,attr"`

	Distance float64       `xml:"-"`
	Latency  time.Duration `xml:"-"`
	// contains filtered or unexported fields
}

func (*Server) DownloadSpeed

func (server *Server) DownloadSpeed() int

func (*Server) MeasureLatency

func (server *Server) MeasureLatency(times uint, errorLatency time.Duration) time.Duration

func (*Server) RelativeURL

func (s *Server) RelativeURL(local string) string

func (*Server) String

func (s *Server) String() string

func (*Server) UploadSpeed

func (server *Server) UploadSpeed() int

type ServerID

type ServerID uint64

type Servers

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

func (*Servers) Find

func (servers *Servers) Find(id ServerID) *Server

func (*Servers) First

func (servers *Servers) First() *Server

func (*Servers) Len

func (servers *Servers) Len() int

func (*Servers) Less

func (servers *Servers) Less(i, j int) bool

func (*Servers) MeasureLatencies

func (servers *Servers) MeasureLatencies(times uint, errorLatency time.Duration) *Servers

Measures latencies for each server. Returns server list sorted by latencies. This is synchronous operation, because multiple simultaneous requests may affect results.

func (*Servers) String

func (servers *Servers) String() string

func (*Servers) Swap

func (servers *Servers) Swap(i, j int)

type ServersRef

type ServersRef struct {
	Servers *Servers
	Error   error
}

Jump to

Keyboard shortcuts

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