Documentation ¶
Index ¶
- Constants
- Variables
- func IsTimeout(err error) bool
- type HIRes
- type LocalInfo
- type PingCallback
- type PingRes
- type SpeedtestClient
- func (sc *SpeedtestClient) GetAllServerList() (servList SpeedtestServerList, err error)
- func (sc *SpeedtestClient) GetLocalInfoAndServerList() (li *LocalInfo, servList SpeedtestServerList, err error)
- func (sc *SpeedtestClient) SetProxy(proxyAddr string)
- func (sc *SpeedtestClient) WithHost(host string) *SpeedtestClientWithHost
- type SpeedtestClientWithHost
- func (sch *SpeedtestClientWithHost) Download(opt *UpDownloadOption, callback UpDownloadCallback) (res *UpDownloadRes, err error)
- func (sch *SpeedtestClientWithHost) HI() (res *HIRes, err error)
- func (sch *SpeedtestClientWithHost) Ping(times int, sleep time.Duration, callback PingCallback) (res *PingRes, err error)
- func (sch *SpeedtestClientWithHost) SetLocalAddr(localAddr *net.TCPAddr)
- func (sch *SpeedtestClientWithHost) SetSocks5Proxy(proxyAddr string) (err error)
- func (sch *SpeedtestClientWithHost) Upload(opt *UpDownloadOption, callback UpDownloadCallback) (res *UpDownloadRes, err error)
- type SpeedtestServer
- type SpeedtestServerList
- type Statistic
- func (s *Statistic) AddTransferSize(size int64) int64
- func (s *Statistic) AppendSpeedPerSecond(speed int64)
- func (s *Statistic) Elapsed() (elapsed time.Duration)
- func (s *Statistic) ElapsedAndLeft() (elapsed, left time.Duration)
- func (s *Statistic) SpeedPerSecond() int64
- func (s *Statistic) StartTimer()
- func (s *Statistic) TotalSize() int64
- func (s *Statistic) TransferSize() int64
- type TimeDurationSlice
- type UpDownloadCallback
- type UpDownloadOption
- type UpDownloadRes
Constants ¶
View Source
const ( // SessionTime speedtest 会话最长时间 SessionTime = 1 * time.Minute PingTimeout = 10 * time.Second HiTimeout = 1 * time.Minute UpDownloadSize = 128 * converter.PB )
View Source
const (
SpeedtestHost = "www.speedtest.net"
)
Variables ¶
Functions ¶
Types ¶
type LocalInfo ¶
type PingCallback ¶
type PingRes ¶
type PingRes struct { Latencies []time.Duration Average time.Duration Min time.Duration Max time.Duration Median time.Duration }
PingRes PING 结果
func NewPingRes ¶
type SpeedtestClient ¶
type SpeedtestClient struct {
// contains filtered or unexported fields
}
func NewSpeedtestClient ¶
func NewSpeedtestClient() *SpeedtestClient
func (*SpeedtestClient) GetAllServerList ¶
func (sc *SpeedtestClient) GetAllServerList() (servList SpeedtestServerList, err error)
func (*SpeedtestClient) GetLocalInfoAndServerList ¶
func (sc *SpeedtestClient) GetLocalInfoAndServerList() (li *LocalInfo, servList SpeedtestServerList, err error)
func (*SpeedtestClient) SetProxy ¶
func (sc *SpeedtestClient) SetProxy(proxyAddr string)
SetProxy 设置代理
func (*SpeedtestClient) WithHost ¶
func (sc *SpeedtestClient) WithHost(host string) *SpeedtestClientWithHost
type SpeedtestClientWithHost ¶
type SpeedtestClientWithHost struct { SpeedtestClient Host string // contains filtered or unexported fields }
func (*SpeedtestClientWithHost) Download ¶
func (sch *SpeedtestClientWithHost) Download(opt *UpDownloadOption, callback UpDownloadCallback) (res *UpDownloadRes, err error)
func (*SpeedtestClientWithHost) HI ¶
func (sch *SpeedtestClientWithHost) HI() (res *HIRes, err error)
func (*SpeedtestClientWithHost) Ping ¶
func (sch *SpeedtestClientWithHost) Ping(times int, sleep time.Duration, callback PingCallback) (res *PingRes, err error)
func (*SpeedtestClientWithHost) SetLocalAddr ¶
func (sch *SpeedtestClientWithHost) SetLocalAddr(localAddr *net.TCPAddr)
func (*SpeedtestClientWithHost) SetSocks5Proxy ¶
func (sch *SpeedtestClientWithHost) SetSocks5Proxy(proxyAddr string) (err error)
func (*SpeedtestClientWithHost) Upload ¶
func (sch *SpeedtestClientWithHost) Upload(opt *UpDownloadOption, callback UpDownloadCallback) (res *UpDownloadRes, err error)
type SpeedtestServer ¶
type SpeedtestServer struct { ID int Name string Sponsor string Lat float64 Lon float64 Host string // contains filtered or unexported fields }
func (*SpeedtestServer) String ¶
func (server *SpeedtestServer) String() string
type SpeedtestServerList ¶
type SpeedtestServerList []*SpeedtestServer
func (SpeedtestServerList) FindByID ¶
func (servList SpeedtestServerList) FindByID(id int) (server *SpeedtestServer)
func (SpeedtestServerList) PrintTo ¶
func (servList SpeedtestServerList) PrintTo(w io.Writer)
type Statistic ¶
type Statistic struct {
// contains filtered or unexported fields
}
Statistic 统计
func (*Statistic) AddTransferSize ¶
func (*Statistic) AppendSpeedPerSecond ¶
func (*Statistic) ElapsedAndLeft ¶
func (*Statistic) SpeedPerSecond ¶
func (*Statistic) StartTimer ¶
func (s *Statistic) StartTimer()
func (*Statistic) TransferSize ¶
type TimeDurationSlice ¶
func (TimeDurationSlice) Len ¶
func (p TimeDurationSlice) Len() int
func (TimeDurationSlice) Less ¶
func (p TimeDurationSlice) Less(i, j int) bool
func (TimeDurationSlice) Swap ¶
func (p TimeDurationSlice) Swap(i, j int)
type UpDownloadCallback ¶
type UpDownloadCallback func(statistic *Statistic)
UpDownloadCallback 上传或下载的回调
type UpDownloadOption ¶
type UpDownloadRes ¶
type UpDownloadRes struct { TimeElapsed time.Duration SpeedsPerSecond []int64 MaxSpeedPerSecond int64 MinSpeedPerSecond int64 AverageSpeed int64 MedianSpeed int64 }
UpDownloadRes 下载或上传的结果
func NewUpDownloadRes ¶
func NewUpDownloadRes(timeElapsed time.Duration, statistic *Statistic) *UpDownloadRes
Click to show internal directories.
Click to hide internal directories.