checker

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckType

type CheckType string

CheckType represents the type of check to perform.

const (
	TCP  CheckType = "TCP" // TCP represents a check over the TCP protocol.
	HTTP CheckType = "HTTP"
	ICMP CheckType = "ICMP"
)

func GetCheckTypeFromString

func GetCheckTypeFromString(checkTypeStr string) (CheckType, error)

GetCheckTypeFromString converts a string to a CheckType enum.

func (CheckType) String

func (c CheckType) String() string

String returns the string representation of the CheckType.

type Checker

type Checker interface {
	Check(ctx context.Context) error // Check performs a check and returns an error if the check fails.
	GetName() string                 // GetName returns the name of the checker.
	GetType() string                 // GetType returns the type of the checker.
	GetAddress() string              // GetAddress returns the address of the checker.
}

Checker defines an interface for performing various types of checks, such as TCP, HTTP, or ICMP. It provides methods for executing the check and obtaining a string representation of the checker.

func NewChecker

func NewChecker(checkType CheckType, name, address string, opts ...Option) (Checker, error)

NewChecker creates a new Checker based on the specified CheckType, name, address, and options.

type HTTPChecker

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

HTTPChecker implements the Checker interface for HTTP checks.

func (*HTTPChecker) Check

func (c *HTTPChecker) Check(ctx context.Context) error

func (*HTTPChecker) GetAddress

func (c *HTTPChecker) GetAddress() string

func (*HTTPChecker) GetName

func (c *HTTPChecker) GetName() string

func (*HTTPChecker) GetType

func (c *HTTPChecker) GetType() string

type ICMPChecker

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

ICMPChecker implements the Checker interface for ICMP checks.

func (*ICMPChecker) Check

func (c *ICMPChecker) Check(ctx context.Context) error

func (*ICMPChecker) GetAddress

func (c *ICMPChecker) GetAddress() string

func (*ICMPChecker) GetName

func (c *ICMPChecker) GetName() string

func (*ICMPChecker) GetType

func (c *ICMPChecker) GetType() string

type ICMPv4

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

ICMPv4 implements the Protocol interface for IPv4 ICMP.

func (*ICMPv4) ListenPacket

func (p *ICMPv4) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)

ListenPacket creates a new ICMPv4 packet connection.

func (*ICMPv4) MakeRequest

func (p *ICMPv4) MakeRequest(identifier, sequence uint16) ([]byte, error)

MakeRequest creates an ICMP echo request message.

func (*ICMPv4) Network

func (p *ICMPv4) Network() string

Network returns the network type for the ICMP protocol.

func (*ICMPv4) SetDeadline

func (p *ICMPv4) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

func (*ICMPv4) ValidateReply

func (p *ICMPv4) ValidateReply(reply []byte, identifier, sequence uint16) error

ValidateReply validates an ICMP echo reply message.

type ICMPv6

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

ICMPv6 implements the Protocol interface for IPv6 ICMP.

func (*ICMPv6) ListenPacket

func (p *ICMPv6) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)

ListenPacket creates a new ICMPv6 packet connection.

func (*ICMPv6) MakeRequest

func (p *ICMPv6) MakeRequest(identifier, sequence uint16) ([]byte, error)

MakeRequest creates an ICMP echo request message.

func (*ICMPv6) Network

func (p *ICMPv6) Network() string

Network returns the network type for the ICMP protocol.

func (*ICMPv6) SetDeadline

func (p *ICMPv6) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

func (*ICMPv6) ValidateReply

func (p *ICMPv6) ValidateReply(reply []byte, identifier, sequence uint16) error

ValidateReply validates an ICMP echo reply message.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option defines a functional option for configuring a Checker.

func WithExpectedStatusCodes

func WithExpectedStatusCodes(codes []int) Option

WithExpectedStatusCodes sets the expected status codes for the HTTPChecker.

func WithHTTPHeaders

func WithHTTPHeaders(headers map[string]string) Option

WithHTTPHeaders sets the HTTP headers for the HTTPChecker.

func WithHTTPMethod

func WithHTTPMethod(method string) Option

WithHTTPMethod sets the HTTP method for the HTTPChecker.

func WithHTTPSkipTLSVerify

func WithHTTPSkipTLSVerify(skip bool) Option

WithHTTPSkipTLSVerify sets the TLS verification flag for the HTTPChecker.

func WithHTTPTimeout

func WithHTTPTimeout(timeout time.Duration) Option

WithHTTPTimeout sets the timeout for the HTTPChecker.

func WithICMPReadTimeout

func WithICMPReadTimeout(timeout time.Duration) Option

WithICMPReadTimeout sets the read timeout for the ICMPChecker.

func WithICMPWriteTimeout

func WithICMPWriteTimeout(timeout time.Duration) Option

WithICMPWriteTimeout sets the write timeout for the ICMPChecker.

func WithTCPTimeout

func WithTCPTimeout(timeout time.Duration) Option

WithTCPTimeout sets the timeout for the TCPChecker.

type OptionFunc

type OptionFunc func(Checker)

OptionFunc is a function that applies an Option to a Checker.

type Protocol

type Protocol interface {
	// MakeRequest creates an ICMP echo request message with the specified identifier and sequence number.
	// Returns the serialized byte representation of the message or an error if message construction fails.
	MakeRequest(identifier, sequence uint16) ([]byte, error)
	// ValidateReply verifies that an ICMP echo reply message matches the expected identifier and sequence number.
	// Returns an error if the reply is invalid, such as a mismatch in identifier, sequence number, or unexpected message type.
	ValidateReply(reply []byte, identifier, sequence uint16) error
	// Network returns the network type string to be used for listening to ICMP packets, which typically indicates the IP
	// protocol version (e.g., "ip4:icmp" for IPv4 ICMP or "ip6:ipv6-icmp" for IPv6 ICMP).
	Network() string
	// ListenPacket sets up a listener for ICMP packets on the specified network and address, using the provided context.
	// Returns a net.PacketConn for reading and writing packets, or an error if the listener cannot be established.
	ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
	// SetDeadline sets the read and write deadlines for the packet connection, affecting any I/O operations on the connection.
	// Returns an error if setting the deadline fails.
	SetDeadline(t time.Time) error
}

Protocol defines an interface for ICMP-based diagnostics, abstracting ICMPv4 and ICMPv6 behavior.

type TCPChecker

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

TCPChecker implements the Checker interface for TCP checks.

func (*TCPChecker) Check

func (c *TCPChecker) Check(ctx context.Context) error

func (*TCPChecker) GetAddress

func (c *TCPChecker) GetAddress() string

func (*TCPChecker) GetName

func (c *TCPChecker) GetName() string

func (*TCPChecker) GetType

func (c *TCPChecker) GetType() string

Jump to

Keyboard shortcuts

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