ping

package
v0.0.0-...-71f2f50 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCounter  = 4
	DefaultInterval = time.Second
	DefaultTimeout  = time.Second * 5
)

Variables

This section is empty.

Functions

func FormatIP

func FormatIP(IP string) (string, error)

FormatIP - trim spaces and format IP.

IP - the provided IP

string - return "" if the input is neither valid IPv4 nor valid IPv6

return IPv4 in format like "192.168.9.1"
return IPv6 in format like "[2002:ac1f:91c5:1::bd59]"

func ParseAddress

func ParseAddress(addr string) (*url.URL, error)

ParseAddress will try to parse addr as url.URL.

func ParseDuration

func ParseDuration(t string) (time.Duration, error)

ParseDuration parse the t as time.Duration, it will parse t as mills when missing unit.

func Register

func Register(protocol Protocol, factory Factory)

Types

type Factory

type Factory func(url *url.URL, op *Option) (Ping, error)

func Load

func Load(protocol Protocol) Factory

type Option

type Option struct {
	Timeout  time.Duration
	Resolver *net.Resolver
	Proxy    *url.URL
	UA       string
}

type Ping

type Ping interface {
	Ping(ctx context.Context) *Stats
}

type Pinger

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

func NewPinger

func NewPinger(out io.Writer, url *url.URL, ping Ping, interval time.Duration, counter int) *Pinger

func (*Pinger) Done

func (p *Pinger) Done() <-chan struct{}

func (*Pinger) Ping

func (p *Pinger) Ping()

func (*Pinger) Stop

func (p *Pinger) Stop()

func (*Pinger) Summarize

func (p *Pinger) Summarize()

type Protocol

type Protocol int

Protocol ...

const (
	// TCP is tcp protocol
	TCP Protocol = iota
	// HTTP is http protocol
	HTTP
	// HTTPS is https protocol
	HTTPS
)

func NewProtocol

func NewProtocol(protocol string) (Protocol, error)

NewProtocol convert protocol string to Protocol

func (Protocol) String

func (protocol Protocol) String() string

type Result

type Result struct {
	Counter        int
	SuccessCounter int
	Target         *Target

	MinDuration   time.Duration
	MaxDuration   time.Duration
	TotalDuration time.Duration
}

Result ...

func (Result) Avg

func (result Result) Avg() time.Duration

Avg return the average time of ping

func (Result) Failed

func (result Result) Failed() int

Failed return failed counter

func (Result) String

func (result Result) String() string

type Stats

type Stats struct {
	Connected   bool                    `json:"connected"`
	Error       error                   `json:"error"`
	Duration    time.Duration           `json:"duration"`
	DNSDuration time.Duration           `json:"DNSDuration"`
	Address     string                  `json:"address"`
	Meta        map[string]fmt.Stringer `json:"meta"`
	Extra       fmt.Stringer            `json:"extra"`
}

func (*Stats) FormatMeta

func (s *Stats) FormatMeta() string

type Target

type Target struct {
	Protocol Protocol
	Host     string
	IP       string
	Port     int
	Proxy    string

	Counter  int
	Interval time.Duration
	Timeout  time.Duration
}

Target is a ping

func (Target) String

func (target Target) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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