ping

package
v0.0.0-...-406c194 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckURI

func CheckURI(uri string) (schema, host string, port int, matched bool)

CheckURI check uri

func FormatIP

func FormatIP(IP string) string

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 GetIP

func GetIP(hostname string) string

GetIP ...

func UseCustomeDNS

func UseCustomeDNS(dns []string)

UseCustomeDNS will set the dns to default DNS resolver for global

Types

type HTTPing

type HTTPing struct {
	Method string
	// contains filtered or unexported fields
}

HTTPing ...

func NewHTTPing

func NewHTTPing(method string) *HTTPing

NewHTTPing return new HTTPing

func (*HTTPing) Result

func (ping *HTTPing) Result() *Result

Result return ping result

func (*HTTPing) SetTarget

func (ping *HTTPing) SetTarget(target *Target)

SetTarget ...

func (*HTTPing) Start

func (ping *HTTPing) Start() <-chan struct{}

Start ping

func (*HTTPing) Stop

func (ping *HTTPing) Stop()

Stop the tcping

type Ping

type Ping interface {
	Start() <-chan struct{}

	Host() string
	Port() int
	Protocol() Protocol
	Counter() int

	Stop()

	Result() Result
}

Ping is a ping interface

type Pinger

type Pinger interface {
	Start() <-chan struct{}
	Stop()
	Result() *Result
	SetTarget(target *Target)
}

Pinger is a ping interface

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 stirng to Protocol

func (Protocol) String

func (protocol Protocol) String() string

type Result

type Result struct {
	Counter        int
	SuccessCounter int
	RemoteAddr     string
	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 TCPing

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

TCPing ...

func NewTCPing

func NewTCPing() *TCPing

NewTCPing return a new TCPing

func (TCPing) Result

func (tcping TCPing) Result() *Result

Result return the result

func (*TCPing) SetTarget

func (tcping *TCPing) SetTarget(target *Target)

SetTarget set target for TCPing

func (TCPing) Start

func (tcping TCPing) Start() <-chan struct{}

Start a tcping

func (*TCPing) Stop

func (tcping *TCPing) Stop()

Stop the tcping

type Target

type Target struct {
	Protocol Protocol
	Host     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

Jump to

Keyboard shortcuts

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