Skip to content

Commit

Permalink
chore: docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiandongx committed May 27, 2024
1 parent f12f0ff commit 78ea077
Show file tree
Hide file tree
Showing 576 changed files with 63 additions and 239,316 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Pinger is a library used to evaluate the quality of services in ICMP/TCP/HTTP protocol.

What's worth pointing out is that `ping` here means not only the standard **IMCP Protocol**, but also **TCP/HTTP/HTTPS**. It's the more general sense here as an approach to detect the network quality.
What's worth pointing out is that `ping` here means not only the standard **ICMP Protocol**, but also **TCP/HTTP/HTTPS**. It's the more general sense here as an approach to detect the network quality.

[![GoDoc](https://godoc.org/github.com/chenjiandongx/pinger?status.svg)](https://godoc.org/github.com/chenjiandongx/pinger)
[![Travis](https://travis-ci.org/chenjiandongx/pinger.svg?branch=master)](https://travis-ci.org/chenjiandongx/pinger)
Expand Down Expand Up @@ -57,18 +57,18 @@ func main() {

**PingTimeout / Interval**
```golang
opts := pinger.DefaultICMPPingOpts
opts := pinger.DefaultICMPPingOpts()
opts.PingTimeout = 50 * time.Millisecond
// sleep 60 mills after a request every time.
opts.Interval = func() time.Duration { return 60 * time.Millisecond }
```

**PingCount / MaxConcurrency / FailOver**
```golang
opts := pinger.DefaultICMPPingOpts
opts := pinger.DefaultICMPPingOpts()
// network is unstable thus we need more ping-ops to evaluate the network quality overall.
opts.PingCount = 20
// set the maximum concurreny, goroutine is cheap, but not free :)
// set the maximum concurrency, goroutine is cheap, but not free :)
opts.MaxConcurrency = 5
// set per host maximum failed allowed
opts.FailOver = 5
Expand All @@ -77,8 +77,8 @@ opts.FailOver = 5
**Headers / Method**
```golang
// in http/https case, there are more options could be used.
opts := pinger.DefaultHTTPPingOpts
// HTTP headers, something speical for authentication or anything else.
opts := pinger.DefaultHTTPPingOpts()
// HTTP headers, something special for authentication or anything else.
opts.Headers = map[string]string{"token": "my-token", "who": "me"}
// HTTP Method, feel free to use any standard HTTP methods you need.
opts.Method = http.MethodPost
Expand Down
16 changes: 12 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
module github.com/chenjiandongx/pinger

go 1.13
go 1.19

require (
github.com/digineo/go-ping v1.0.0
github.com/sirupsen/logrus v1.5.0
github.com/stretchr/testify v1.2.2
github.com/digineo/go-ping v1.1.0
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/digineo/go-logwrap v0.0.0-20181106161722-a178c58ea3f0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
36 changes: 12 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,17 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digineo/go-logwrap v0.0.0-20181106161722-a178c58ea3f0 h1:OT/LKmj81wMymnWXaKaKBR9n1vPlu+GC0VVKaZP6kzs=
github.com/digineo/go-logwrap v0.0.0-20181106161722-a178c58ea3f0/go.mod h1:DmqdumeAKGQNU5E8MN0ruT5ZGx8l/WbAsMbXCXcSEts=
github.com/digineo/go-ping v1.0.0 h1:gOuD3YzkIcW/0Y2IAe27bsMKtpfNZdoX1Rnc1RGYOSI=
github.com/digineo/go-ping v1.0.0/go.mod h1:YLDBnHoAygacawa2aubI4vXhZ4do5f62oJSvRiJVEjw=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.1.1/go.mod h1:K1udHkiR3cOtlpKG5tZPD5XxrF7v2y7lDq7Whcj+xkQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08/go.mod h1:NXg0ArsFk0Y01623LgUqoqcouGDB+PwCCQlrwrG6xJ4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/digineo/go-ping v1.1.0 h1:HXZPBw8/Zk+tFuHrHejBTLopcEkqK4FNn1ocqKo6xhw=
github.com/digineo/go-ping v1.1.0/go.mod h1:rVhwm0cbn6i20vX/MBmo4OoxOvAW/6JiIf+2Oln8n0M=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/tview v0.0.0-20181226202439-36893a669792/go.mod h1:J4W+hErFfITUbyFAEXizpmkuxX7ZN56dopxHB4XQhMw=
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw=
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
22 changes: 12 additions & 10 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ type HTTPPingOpts struct {
}

// DefaultHTTPPingOpts will be used if PingOpts is nil with the HTTPPing function.
var DefaultHTTPPingOpts = &HTTPPingOpts{
PingTimeout: 3 * time.Second,
PingCount: 10,
Method: http.MethodGet,
Body: nil,
Headers: nil,
Interval: func() time.Duration { return time.Duration(rand.Int63n(200)) * time.Millisecond },
MaxConcurrency: 10,
FailOver: 5,
func DefaultHTTPPingOpts() *HTTPPingOpts {
return &HTTPPingOpts{
PingTimeout: 3 * time.Second,
PingCount: 10,
Method: http.MethodGet,
Body: nil,
Headers: nil,
Interval: func() time.Duration { return time.Duration(rand.Int63n(200)) * time.Millisecond },
MaxConcurrency: 10,
FailOver: 5,
}
}

func (opts *HTTPPingOpts) ping(dest *destination, args ...interface{}) error {
Expand Down Expand Up @@ -78,7 +80,7 @@ func (opts *HTTPPingOpts) ping(dest *destination, args ...interface{}) error {

func HTTPPing(opts *HTTPPingOpts, hosts ...string) ([]PingStat, error) {
if opts == nil {
opts = DefaultHTTPPingOpts
opts = DefaultHTTPPingOpts()
}

var transport = &http.Transport{
Expand Down
22 changes: 12 additions & 10 deletions icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ type ICMPPingOpts struct {
}

// DefaultICMPPingOpts will be used if PingOpts is nil with the ICMPPing function.
var DefaultICMPPingOpts = &ICMPPingOpts{
PingTimeout: 3 * time.Second,
PingCount: 10,
MaxConcurrency: 10,
FailOver: 5,
Interval: func() time.Duration { return time.Duration(rand.Int63n(200)) * time.Millisecond },
Bind4: "0.0.0.0",
ResolverTimeout: 1500 * time.Millisecond,
PayloadSize: 56,
func DefaultICMPPingOpts() *ICMPPingOpts {
return &ICMPPingOpts{
PingTimeout: 3 * time.Second,
PingCount: 10,
MaxConcurrency: 10,
FailOver: 5,
Interval: func() time.Duration { return time.Duration(rand.Int63n(200)) * time.Millisecond },
Bind4: "0.0.0.0",
ResolverTimeout: 1500 * time.Millisecond,
PayloadSize: 56,
}
}

func (opts *ICMPPingOpts) ping(dest *destination, args ...interface{}) error {
Expand All @@ -49,7 +51,7 @@ func (opts *ICMPPingOpts) ping(dest *destination, args ...interface{}) error {

func ICMPPing(opts *ICMPPingOpts, hosts ...string) ([]PingStat, error) {
if opts == nil {
opts = DefaultICMPPingOpts
opts = DefaultICMPPingOpts()
}

pinger := &ping.Pinger{}
Expand Down
16 changes: 9 additions & 7 deletions tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ type TCPPingOpts struct {
}

// DefaultTCPPingOpts will be used if PingOpts is nil with the TCPPing function.
var DefaultTCPPingOpts = &TCPPingOpts{
PingTimeout: 3 * time.Second,
PingCount: 10,
Interval: func() time.Duration { return time.Duration(rand.Int63n(200)) * time.Millisecond },
MaxConcurrency: 10,
FailOver: 5,
func DefaultTCPPingOpts() *TCPPingOpts {
return &TCPPingOpts{
PingTimeout: 3 * time.Second,
PingCount: 10,
Interval: func() time.Duration { return time.Duration(rand.Int63n(200)) * time.Millisecond },
MaxConcurrency: 10,
FailOver: 5,
}
}

func (opts *TCPPingOpts) ping(dest *destination, args ...interface{}) error {
Expand All @@ -47,7 +49,7 @@ func (opts *TCPPingOpts) ping(dest *destination, args ...interface{}) error {

func TCPPing(opts *TCPPingOpts, hosts ...string) ([]PingStat, error) {
if opts == nil {
opts = DefaultTCPPingOpts
opts = DefaultTCPPingOpts()
}

dests := make([]*destination, 0)
Expand Down
15 changes: 0 additions & 15 deletions vendor/github.com/davecgh/go-spew/LICENSE

This file was deleted.

145 changes: 0 additions & 145 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

This file was deleted.

Loading

0 comments on commit 78ea077

Please sign in to comment.