network

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package network provides concrete implementations of network diagnostic operations

Package network provides mock implementations for testing

Package network provides network operation implementations

Package network provides retry logic for network operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements the NetworkClient interface with real network operations

func NewClient

func NewClient(config *domain.NetworkConfig, errorHandler domain.ErrorHandler, logger domain.Logger) *Client

NewClient creates a new network client with the provided configuration

func (*Client) DNSLookup

func (c *Client) DNSLookup(ctx context.Context, domainName string, recordType domain.DNSRecordType) (domain.DNSResult, error)

DNSLookup performs DNS lookups for the specified domain and record type

func (*Client) Ping

func (c *Client) Ping(ctx context.Context, host string, opts domain.PingOptions) (<-chan domain.PingResult, error)

Ping performs ping operations to the specified host

func (*Client) SSLCheck

func (c *Client) SSLCheck(ctx context.Context, host string, port int) (domain.SSLResult, error)

SSLCheck performs SSL certificate checks for the specified host and port

func (*Client) Traceroute

func (c *Client) Traceroute(ctx context.Context, host string, opts domain.TraceOptions) (<-chan domain.TraceHop, error)

Traceroute performs traceroute operations to the specified host

func (*Client) WHOISLookup

func (c *Client) WHOISLookup(ctx context.Context, query string) (domain.WHOISResult, error)

WHOISLookup performs WHOIS lookups for the specified query

type MockCall

type MockCall struct {
	Method    string
	Args      []interface{}
	Timestamp time.Time
}

MockCall represents a recorded method call

type MockClient

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

MockClient implements the NetworkClient interface for testing

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock network client

func (*MockClient) DNSLookup

func (m *MockClient) DNSLookup(ctx context.Context, domainName string, recordType domain.DNSRecordType) (domain.DNSResult, error)

DNSLookup implements the NetworkClient interface with mock behavior

func (*MockClient) GetCallCount

func (m *MockClient) GetCallCount() int

GetCallCount returns the total number of method calls made

func (*MockClient) GetDNSCalls

func (m *MockClient) GetDNSCalls() []MockCall

GetDNSCalls returns all recorded DNS calls

func (*MockClient) GetPingCalls

func (m *MockClient) GetPingCalls() []MockCall

GetPingCalls returns all recorded ping calls

func (*MockClient) GetSSLCalls

func (m *MockClient) GetSSLCalls() []MockCall

GetSSLCalls returns all recorded SSL calls

func (*MockClient) GetTraceCalls

func (m *MockClient) GetTraceCalls() []MockCall

GetTraceCalls returns all recorded traceroute calls

func (*MockClient) GetWHOISCalls

func (m *MockClient) GetWHOISCalls() []MockCall

GetWHOISCalls returns all recorded WHOIS calls

func (*MockClient) Ping

func (m *MockClient) Ping(ctx context.Context, host string, opts domain.PingOptions) (<-chan domain.PingResult, error)

Ping implements the NetworkClient interface with mock behavior

func (*MockClient) Reset

func (m *MockClient) Reset()

Reset clears all recorded calls and configured responses

func (*MockClient) SSLCheck

func (m *MockClient) SSLCheck(ctx context.Context, host string, port int) (domain.SSLResult, error)

SSLCheck implements the NetworkClient interface with mock behavior

func (*MockClient) SetDNSError

func (m *MockClient) SetDNSError(domainName string, recordType domain.DNSRecordType, err error)

SetDNSError configures a mock DNS error for a specific domain and record type

func (*MockClient) SetDNSResponse

func (m *MockClient) SetDNSResponse(domainName string, recordType domain.DNSRecordType, result domain.DNSResult)

SetDNSResponse configures a mock DNS response for a specific domain and record type

func (*MockClient) SetPingDelay

func (m *MockClient) SetPingDelay(host string, delay time.Duration)

SetPingDelay configures a mock ping delay for a specific host

func (*MockClient) SetPingError

func (m *MockClient) SetPingError(host string, err error)

SetPingError configures a mock ping error for a specific host

func (*MockClient) SetPingResponse

func (m *MockClient) SetPingResponse(host string, results []domain.PingResult)

SetPingResponse configures a mock ping response for a specific host

func (*MockClient) SetSSLError

func (m *MockClient) SetSSLError(host string, port int, err error)

SetSSLError configures a mock SSL error for a specific host and port

func (*MockClient) SetSSLResponse

func (m *MockClient) SetSSLResponse(host string, port int, result domain.SSLResult)

SetSSLResponse configures a mock SSL response for a specific host and port

func (*MockClient) SetSimulateNetworkError

func (m *MockClient) SetSimulateNetworkError(simulate bool)

SetSimulateNetworkError enables or disables network error simulation

func (*MockClient) SetSimulateTimeout

func (m *MockClient) SetSimulateTimeout(simulate bool)

SetSimulateTimeout enables or disables timeout simulation

func (*MockClient) SetTraceError

func (m *MockClient) SetTraceError(host string, err error)

SetTraceError configures a mock traceroute error for a specific host

func (*MockClient) SetTraceResponse

func (m *MockClient) SetTraceResponse(host string, hops []domain.TraceHop)

SetTraceResponse configures a mock traceroute response for a specific host

func (*MockClient) SetWHOISError

func (m *MockClient) SetWHOISError(query string, err error)

SetWHOISError configures a mock WHOIS error for a specific query

func (*MockClient) SetWHOISResponse

func (m *MockClient) SetWHOISResponse(query string, result domain.WHOISResult)

SetWHOISResponse configures a mock WHOIS response for a specific query

func (*MockClient) Traceroute

func (m *MockClient) Traceroute(ctx context.Context, host string, opts domain.TraceOptions) (<-chan domain.TraceHop, error)

Traceroute implements the NetworkClient interface with mock behavior

func (*MockClient) WHOISLookup

func (m *MockClient) WHOISLookup(ctx context.Context, query string) (domain.WHOISResult, error)

WHOISLookup implements the NetworkClient interface with mock behavior

type RetryManager

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

RetryManager handles retry logic for network operations

func NewRetryManager

func NewRetryManager(maxAttempts int, baseDelay time.Duration) *RetryManager

NewRetryManager creates a new retry manager with the specified configuration

func (*RetryManager) ExecuteWithCustomRetry

func (rm *RetryManager) ExecuteWithCustomRetry(ctx context.Context, fn RetryableFunc, shouldRetry ShouldRetryFunc, delayFunc func(int) time.Duration) (interface{}, error)

ExecuteWithCustomRetry executes a function with custom retry logic

func (*RetryManager) ExecuteWithLinearRetry

func (rm *RetryManager) ExecuteWithLinearRetry(ctx context.Context, fn RetryableFunc, shouldRetry ShouldRetryFunc) (interface{}, error)

ExecuteWithLinearRetry executes a function with linear backoff retry logic

func (*RetryManager) ExecuteWithRetry

func (rm *RetryManager) ExecuteWithRetry(ctx context.Context, fn RetryableFunc, shouldRetry ShouldRetryFunc) (interface{}, error)

ExecuteWithRetry executes a function with exponential backoff retry logic

func (*RetryManager) GetBaseDelay

func (rm *RetryManager) GetBaseDelay() time.Duration

GetBaseDelay returns the base delay for retry operations

func (*RetryManager) GetMaxAttempts

func (rm *RetryManager) GetMaxAttempts() int

GetMaxAttempts returns the maximum number of retry attempts

func (*RetryManager) SetBaseDelay

func (rm *RetryManager) SetBaseDelay(baseDelay time.Duration)

SetBaseDelay updates the base delay for retry operations

func (*RetryManager) SetMaxAttempts

func (rm *RetryManager) SetMaxAttempts(maxAttempts int)

SetMaxAttempts updates the maximum number of retry attempts

type RetryableFunc

type RetryableFunc func() (interface{}, error)

RetryableFunc represents a function that can be retried

type ShouldRetryFunc

type ShouldRetryFunc func(error) bool

ShouldRetryFunc determines if an error should trigger a retry

Jump to

Keyboard shortcuts

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