Documentation ¶
Index ¶
- Constants
- Variables
- func PrintCityList()
- func SetUnit(unit UnitType)
- func StandardDeviation(vector []int64) (mean, variance, stdDev, min, max int64)
- func Version() string
- type ByDistance
- type ByteRate
- type Chunk
- type DataChunk
- func (dc *DataChunk) DownloadHandler(r io.Reader) error
- func (dc *DataChunk) GetDuration() time.Duration
- func (dc *DataChunk) GetParent() Manager
- func (dc *DataChunk) GetRate() float64
- func (dc *DataChunk) Read(b []byte) (n int, err error)
- func (dc *DataChunk) UploadHandler(size int64) Chunk
- func (dc *DataChunk) WriteTo(w io.Writer) (written int64, err error)
- type DataManager
- func (dm *DataManager) AddTotalDownload(value int64)
- func (dm *DataManager) AddTotalUpload(value int64)
- func (dm *DataManager) GetAvgDownloadRate() float64
- func (dm *DataManager) GetAvgUploadRate() float64
- func (dm *DataManager) GetEWMADownloadRate() float64
- func (dm *DataManager) GetEWMAUploadRate() float64
- func (dm *DataManager) GetTotalDownload() int64
- func (dm *DataManager) GetTotalUpload() int64
- func (dm *DataManager) NewChunk() Chunk
- func (dm *DataManager) NewDataDirection(testType int) *TestDirection
- func (dm *DataManager) RegisterDownloadHandler(fn func()) *TestDirection
- func (dm *DataManager) RegisterUploadHandler(fn func()) *TestDirection
- func (dm *DataManager) Reset()
- func (dm *DataManager) SetCallbackDownload(callback func(downRate ByteRate))
- func (dm *DataManager) SetCallbackUpload(callback func(upRate ByteRate))
- func (dm *DataManager) SetCaptureTime(duration time.Duration) Manager
- func (dm *DataManager) SetNThread(n int) Manager
- func (dm *DataManager) SetRateCaptureFrequency(duration time.Duration) Manager
- func (dm *DataManager) Snapshots() *Snapshots
- func (dm *DataManager) Wait()
- type DataType
- type Debug
- type Location
- type Manager
- type Option
- type PacketLossAnalyzer
- func (pla *PacketLossAnalyzer) Run(host string, callback func(packetLoss *transport.PLoss)) error
- func (pla *PacketLossAnalyzer) RunMulti(hosts []string) (*transport.PLoss, error)
- func (pla *PacketLossAnalyzer) RunMultiWithContext(ctx context.Context, hosts []string) (*transport.PLoss, error)
- func (pla *PacketLossAnalyzer) RunWithContext(ctx context.Context, host string, callback func(packetLoss *transport.PLoss)) error
- type PacketLossAnalyzerOptions
- type Proto
- type Server
- func (s *Server) CheckResultValid() bool
- func (s *Server) DownloadTest() error
- func (s *Server) DownloadTestContext(ctx context.Context) error
- func (s *Server) HTTPPing(ctx context.Context, echoTimes int, echoFreq time.Duration, ...) (latencies []int64, err error)
- func (s *Server) ICMPPing(ctx context.Context, readTimeout time.Duration, echoTimes int, ...) (latencies []int64, err error)
- func (s *Server) MultiDownloadTestContext(ctx context.Context, servers Servers) error
- func (s *Server) MultiUploadTestContext(ctx context.Context, servers Servers) error
- func (s *Server) PingTest(callback func(latency time.Duration)) error
- func (s *Server) PingTestContext(ctx context.Context, callback func(latency time.Duration)) (err error)
- func (s *Server) String() string
- func (s *Server) TCPPing(ctx context.Context, echoTimes int, echoFreq time.Duration, ...) (latencies []int64, err error)
- func (s *Server) TestAll() error
- func (s *Server) UploadTest() error
- func (s *Server) UploadTestContext(ctx context.Context) error
- type ServerList
- type Servers
- type Snapshot
- type Snapshots
- type Speedtest
- func (s *Speedtest) CustomServer(host string) (*Server, error)
- func (s *Speedtest) FetchServerByID(serverID string) (*Server, error)
- func (s *Speedtest) FetchServerByIDContext(ctx context.Context, serverID string) (*Server, error)
- func (s *Speedtest) FetchServerListContext(ctx context.Context) (Servers, error)
- func (s *Speedtest) FetchServers() (Servers, error)
- func (s *Speedtest) FetchUserInfo() (*User, error)
- func (s *Speedtest) FetchUserInfoContext(ctx context.Context) (*User, error)
- func (s *Speedtest) JSON(servers Servers) ([]byte, error)
- func (s *Speedtest) NewUserConfig(uc *UserConfig)
- func (s *Speedtest) RoundTrip(req *http.Request) (*http.Response, error)
- type TestDirection
- type TestDuration
- type UnitType
- type User
- type UserConfig
- type Users
Constants ¶
const ( UnitTypeDecimalBits = UnitType(iota) // auto scaled UnitTypeDecimalBytes // auto scaled UnitTypeBinaryBits // auto scaled UnitTypeBinaryBytes // auto scaled UnitTypeDefaultMbps // fixed )
IEC and SI
const ( B = 1.0 KB = 1000 * B MB = 1000 * KB GB = 1000 * MB IB = 1 KiB = 1024 * IB MiB = 1024 * KiB GiB = 1024 * MiB )
const PingTimeout = -1
Variables ¶
var ( DecimalBitsUnits = []string{"bps", "Kbps", "Mbps", "Gbps"} DecimalBytesUnits = []string{"B/s", "KB/s", "MB/s", "GB/s"} BinaryBitsUnits = []string{"Kibps", "KiMbps", "KiGbps"} BinaryBytesUnits = []string{"KiB/s", "MiB/s", "GiB/s"} )
var (
DefaultUserAgent = fmt.Sprintf("showwin/speedtest-go %s", version)
)
var (
ErrConnectTimeout = errors.New("server connect timeout")
)
var (
ErrServerNotFound = errors.New("no server available or found")
)
var (
ErrorUninitializedManager = errors.New("uninitialized manager")
)
var Locations = map[string]*Location{
"brasilia": {"brasilia", "br", -15.793876, -47.8835327},
"hongkong": {"hongkong", "hk", 22.3106806, 114.1700546},
"tokyo": {"tokyo", "jp", 35.680938, 139.7674114},
"london": {"london", "uk", 51.5072493, -0.1288861},
"moscow": {"moscow", "ru", 55.7497248, 37.615989},
"beijing": {"beijing", "cn", 39.8721243, 116.4077473},
"paris": {"paris", "fr", 48.8626026, 2.3477229},
"sanfrancisco": {"sanfrancisco", "us", 37.7540028, -122.4429967},
"newyork": {"newyork", "us", 40.7200876, -74.0220945},
"yishun": {"yishun", "sg", 1.4230218, 103.8404728},
"delhi": {"delhi", "in", 28.6251287, 77.1960896},
"monterrey": {"monterrey", "mx", 25.6881435, -100.3073485},
"berlin": {"berlin", "de", 52.5168128, 13.4009469},
"maputo": {"maputo", "mz", -25.9579267, 32.5760444},
"honolulu": {"honolulu", "us", 20.8247065, -156.918706},
"seoul": {"seoul", "kr", 37.6086268, 126.7179721},
"osaka": {"osaka", "jp", 34.6952743, 135.5006967},
"shanghai": {"shanghai", "cn", 31.2292105, 121.4661666},
"urumqi": {"urumqi", "cn", 43.8256624, 87.6058564},
"ottawa": {"ottawa", "ca", 45.4161836, -75.7035467},
"capetown": {"capetown", "za", -33.9391993, 18.4316716},
"sydney": {"sydney", "au", -33.8966622, 151.1731861},
"perth": {"perth", "au", -31.9551812, 115.8591904},
"warsaw": {"warsaw", "pl", 52.2396659, 21.0129345},
"kampala": {"kampala", "ug", 0.3070027, 32.5675581},
"bangkok": {"bangkok", "th", 13.7248936, 100.493026},
}
Locations TODO more location need to added
Functions ¶
func PrintCityList ¶
func PrintCityList()
func StandardDeviation ¶
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 ByteRate ¶
type ByteRate float64
type DataChunk ¶
type DataChunk struct { ContentLength int64 // contains filtered or unexported fields }
func (*DataChunk) DownloadHandler ¶
DownloadHandler No value will be returned here, because the error will interrupt the test. The error chunk is generally caused by the remote server actively closing the connection.
func (*DataChunk) GetDuration ¶
func (*DataChunk) Read ¶
Please don't call it, only used to wrapped by io.NopCloser We use DataChunk.WriteTo that implements io.WriterTo to bypass this function.
func (*DataChunk) UploadHandler ¶
type DataManager ¶
type DataManager struct { SnapshotStore *Snapshots Snapshot *Snapshot sync.Mutex // contains filtered or unexported fields }
func NewDataManager ¶
func NewDataManager() *DataManager
func (*DataManager) AddTotalDownload ¶
func (dm *DataManager) AddTotalDownload(value int64)
func (*DataManager) AddTotalUpload ¶
func (dm *DataManager) AddTotalUpload(value int64)
func (*DataManager) GetAvgDownloadRate ¶
func (dm *DataManager) GetAvgDownloadRate() float64
func (*DataManager) GetAvgUploadRate ¶
func (dm *DataManager) GetAvgUploadRate() float64
func (*DataManager) GetEWMADownloadRate ¶
func (dm *DataManager) GetEWMADownloadRate() float64
func (*DataManager) GetEWMAUploadRate ¶
func (dm *DataManager) GetEWMAUploadRate() float64
func (*DataManager) GetTotalDownload ¶
func (dm *DataManager) GetTotalDownload() int64
func (*DataManager) GetTotalUpload ¶
func (dm *DataManager) GetTotalUpload() int64
func (*DataManager) NewChunk ¶
func (dm *DataManager) NewChunk() Chunk
func (*DataManager) NewDataDirection ¶
func (dm *DataManager) NewDataDirection(testType int) *TestDirection
func (*DataManager) RegisterDownloadHandler ¶
func (dm *DataManager) RegisterDownloadHandler(fn func()) *TestDirection
func (*DataManager) RegisterUploadHandler ¶
func (dm *DataManager) RegisterUploadHandler(fn func()) *TestDirection
func (*DataManager) Reset ¶
func (dm *DataManager) Reset()
func (*DataManager) SetCallbackDownload ¶
func (dm *DataManager) SetCallbackDownload(callback func(downRate ByteRate))
func (*DataManager) SetCallbackUpload ¶
func (dm *DataManager) SetCallbackUpload(callback func(upRate ByteRate))
func (*DataManager) SetCaptureTime ¶
func (dm *DataManager) SetCaptureTime(duration time.Duration) Manager
func (*DataManager) SetNThread ¶
func (dm *DataManager) SetNThread(n int) Manager
func (*DataManager) SetRateCaptureFrequency ¶
func (dm *DataManager) SetRateCaptureFrequency(duration time.Duration) Manager
func (*DataManager) Snapshots ¶
func (dm *DataManager) Snapshots() *Snapshots
func (*DataManager) Wait ¶
func (dm *DataManager) Wait()
type Location ¶
func GetLocation ¶
func NewLocation ¶
NewLocation new a Location
func ParseLocation ¶
ParseLocation parse latitude and longitude string
type Manager ¶
type Manager interface { SetRateCaptureFrequency(duration time.Duration) Manager SetCaptureTime(duration time.Duration) Manager NewChunk() Chunk GetTotalDownload() int64 GetTotalUpload() int64 AddTotalDownload(value int64) AddTotalUpload(value int64) GetAvgDownloadRate() float64 GetAvgUploadRate() float64 GetEWMADownloadRate() float64 GetEWMAUploadRate() float64 SetCallbackDownload(callback func(downRate ByteRate)) SetCallbackUpload(callback func(upRate ByteRate)) RegisterDownloadHandler(fn func()) *TestDirection RegisterUploadHandler(fn func()) *TestDirection // Wait for the upload or download task to end to avoid errors caused by core occupation Wait() Reset() Snapshots() *Snapshots SetNThread(n int) Manager }
type Option ¶
type Option func(*Speedtest)
Option is a function that can be passed to New to modify the Client.
func WithUserConfig ¶
func WithUserConfig(userConfig *UserConfig) Option
WithUserConfig adds a custom user config for speedtest. This configuration may be overwritten again by WithDoer, because client and transport are parent-child relationship: `New(WithDoer(myDoer), WithUserAgent(myUserAgent), WithDoer(myDoer))`
type PacketLossAnalyzer ¶
type PacketLossAnalyzer struct {
// contains filtered or unexported fields
}
func NewPacketLossAnalyzer ¶
func NewPacketLossAnalyzer(options *PacketLossAnalyzerOptions) *PacketLossAnalyzer
func (*PacketLossAnalyzer) Run ¶
func (pla *PacketLossAnalyzer) Run(host string, callback func(packetLoss *transport.PLoss)) error
func (*PacketLossAnalyzer) RunMulti ¶
func (pla *PacketLossAnalyzer) RunMulti(hosts []string) (*transport.PLoss, error)
RunMulti Mix all servers to get the average packet loss.
func (*PacketLossAnalyzer) RunMultiWithContext ¶
func (*PacketLossAnalyzer) RunWithContext ¶
type PacketLossAnalyzerOptions ¶
type PacketLossAnalyzerOptions struct { RemoteSamplingInterval time.Duration SamplingDuration time.Duration PacketSendingInterval time.Duration PacketSendingTimeout time.Duration SourceInterface string // source interface TCPDialer *net.Dialer // tcp dialer for sampling UDPDialer *net.Dialer // udp dialer for sending packet }
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"` Host string `xml:"host,attr" json:"host"` Distance float64 `json:"distance"` Latency time.Duration `json:"latency"` MaxLatency time.Duration `json:"max_latency"` MinLatency time.Duration `json:"min_latency"` Jitter time.Duration `json:"jitter"` DLSpeed ByteRate `json:"dl_speed"` ULSpeed ByteRate `json:"ul_speed"` TestDuration TestDuration `json:"test_duration"` PacketLoss transport.PLoss `json:"packet_loss"` Context *Speedtest `json:"-"` }
Server information
func CustomServer ¶
CustomServer use defaultClient, given a URL string, return a new Server object, with as much filled in as we can
func FetchServerByID ¶
FetchServerByID retrieves a server by given serverID.
func (*Server) CheckResultValid ¶
CheckResultValid checks that results are logical given UL and DL speeds
func (*Server) DownloadTest ¶
DownloadTest executes the test to measure download speed
func (*Server) DownloadTestContext ¶
DownloadTestContext executes the test to measure download speed, observing the given context.
func (*Server) ICMPPing ¶
func (s *Server) ICMPPing( ctx context.Context, readTimeout time.Duration, echoTimes int, echoFreq time.Duration, callback func(latency time.Duration), ) (latencies []int64, err error)
ICMPPing privileged method
func (*Server) MultiDownloadTestContext ¶
func (*Server) MultiUploadTestContext ¶
func (*Server) PingTestContext ¶
func (s *Server) PingTestContext(ctx context.Context, callback func(latency time.Duration)) (err error)
PingTestContext executes test to measure latency, observing the given context.
func (*Server) UploadTest ¶
UploadTest executes the test to measure upload speed
type ServerList ¶
ServerList list of Server Users(Client) also exists with @param speedTestServersAdvanced
func (ServerList) String ¶
func (servers ServerList) String() string
String representation of ServerList
type Servers ¶
type Servers []*Server
Servers for sorting servers.
func FetchServerListContext ¶
FetchServerListContext retrieves a list of available servers, observing the given context.
func FetchServers ¶
FetchServers retrieves a list of available servers
func (Servers) FindServer ¶
FindServer finds server by serverID in given server list. If the id is not found in the given list, return the server with the lowest latency.
type Speedtest ¶
Speedtest is a speedtest client.
func (*Speedtest) CustomServer ¶
CustomServer given a URL string, return a new Server object, with as much filled in as we can
func (*Speedtest) FetchServerByID ¶
FetchServerByID retrieves a server by given serverID.
func (*Speedtest) FetchServerByIDContext ¶
FetchServerByIDContext retrieves a server by given serverID, observing the given context.
func (*Speedtest) FetchServerListContext ¶
FetchServerListContext retrieves a list of available servers, observing the given context.
func (*Speedtest) FetchServers ¶
FetchServers retrieves a list of available servers
func (*Speedtest) FetchUserInfo ¶
FetchUserInfo returns information about caller determined by speedtest.net
func (*Speedtest) FetchUserInfoContext ¶
FetchUserInfoContext returns information about caller determined by speedtest.net, observing the given context.
func (*Speedtest) NewUserConfig ¶
func (s *Speedtest) NewUserConfig(uc *UserConfig)
type TestDirection ¶
type TestDirection struct { TestType int // test type RateSequence []int64 // rate history sequence // contains filtered or unexported fields }
func (*TestDirection) AddTotalDataVolume ¶
func (td *TestDirection) AddTotalDataVolume(delta int64) int64
func (*TestDirection) GetTotalDataVolume ¶
func (td *TestDirection) GetTotalDataVolume() int64
func (*TestDirection) Start ¶
func (td *TestDirection) Start(cancel context.CancelFunc, mainRequestHandlerIndex int)
type TestDuration ¶
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"` }
User represents information determined about the caller by speedtest.net
func FetchUserInfo ¶
FetchUserInfo returns information about caller determined by speedtest.net
func FetchUserInfoContext ¶
FetchUserInfoContext returns information about caller determined by speedtest.net, observing the given context.
type UserConfig ¶
type UserConfig struct { T *http.Transport UserAgent string Proxy string Source string DnsBindSource bool DialerControl func(network, address string, c syscall.RawConn) error Debug bool PingMode Proto SavingMode bool MaxConnections int CityFlag string LocationFlag string Location *Location Keyword string // Fuzzy search }