network

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package network provides network diagnostics and health checking capabilities.

Index

Constants

View Source
const (
	// DefaultTimeout for diagnostic tests.
	DefaultTimeout = 30 * time.Second

	// DefaultDNSTimeout for DNS resolution.
	DefaultDNSTimeout = 5 * time.Second

	// DefaultConnTimeout for connectivity tests.
	DefaultConnTimeout = 10 * time.Second

	// BandwidthTestDuration for bandwidth tests.
	BandwidthTestDuration = 10 * time.Second

	// BandwidthTestSize for bandwidth tests (1MB).
	BandwidthTestSize = 1024 * 1024
)

Default constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type BandwidthResult

type BandwidthResult struct {
	DownloadSpeed  float64       `json:"download_speed_mbps"`
	UploadSpeed    float64       `json:"upload_speed_mbps"`
	Latency        time.Duration `json:"latency"`
	PacketLoss     float64       `json:"packet_loss_percent"`
	TestDuration   time.Duration `json:"test_duration"`
	TestServerHost string        `json:"test_server_host"`
	RecommendedUse string        `json:"recommended_use"`
}

BandwidthResult represents bandwidth test results.

type DiagnosticOptions

type DiagnosticOptions struct {
	Timeout          time.Duration
	TestHosts        []string
	DNSServers       []string
	BandwidthServers []string
	IncludeBandwidth bool
	IncludeProxy     bool
	Verbose          bool
}

DiagnosticOptions configures diagnostic behavior.

type DiagnosticResult

type DiagnosticResult struct {
	TestName    string                 `json:"test_name"`
	Success     bool                   `json:"success"`
	Duration    time.Duration          `json:"duration"`
	Error       error                  `json:"error,omitempty"`
	Details     map[string]interface{} `json:"details,omitempty"`
	Timestamp   time.Time              `json:"timestamp"`
	Suggestions []string               `json:"suggestions,omitempty"`
}

DiagnosticResult represents the result of a network diagnostic test.

type Diagnostics

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

Diagnostics provides network diagnostic capabilities.

func NewDiagnostics

func NewDiagnostics() *Diagnostics

NewDiagnostics creates a new network diagnostics instance.

func (*Diagnostics) DetectProxy

func (d *Diagnostics) DetectProxy(ctx context.Context) interface{}

DetectProxy detects proxy configuration and validates it.

func (*Diagnostics) RunFullDiagnostics

func (d *Diagnostics) RunFullDiagnostics(
	ctx context.Context,
	options *DiagnosticOptions,
) (*NetworkHealth, error)

RunFullDiagnostics performs a comprehensive network health check.

func (*Diagnostics) TestBandwidth

func (d *Diagnostics) TestBandwidth(ctx context.Context, testServer string) interface{}

TestBandwidth performs a bandwidth test.

func (*Diagnostics) TestConnectivity

func (d *Diagnostics) TestConnectivity(ctx context.Context, testHosts []string) DiagnosticResult

TestConnectivity tests basic connectivity to multiple hosts.

func (*Diagnostics) TestDNSResolution

func (d *Diagnostics) TestDNSResolution(
	ctx context.Context,
	dnsServers, testHosts []string,
) DiagnosticResult

TestDNSResolution tests DNS resolution for multiple hosts and DNS servers.

func (*Diagnostics) WithDNSServers

func (d *Diagnostics) WithDNSServers(servers []string) *Diagnostics

WithDNSServers sets the DNS servers to test.

func (*Diagnostics) WithTestHosts

func (d *Diagnostics) WithTestHosts(hosts []string) *Diagnostics

WithTestHosts sets the hosts to test connectivity against.

func (*Diagnostics) WithTimeout

func (d *Diagnostics) WithTimeout(timeout time.Duration) *Diagnostics

WithTimeout sets the diagnostic timeout.

func (*Diagnostics) WithVerbose

func (d *Diagnostics) WithVerbose(verbose bool) *Diagnostics

WithVerbose enables verbose output.

type HealthStatus

type HealthStatus int
const (
	// HealthGood indicates good network health.
	HealthGood HealthStatus = iota

	// HealthWarning indicates some network issues.
	HealthWarning

	// HealthPoor indicates significant network problems.
	HealthPoor

	// HealthCritical indicates critical network issues.
	HealthCritical
)

func (HealthStatus) String

func (hs HealthStatus) String() string

String returns the string representation of HealthStatus.

type NetworkHealth

type NetworkHealth struct {
	OverallStatus HealthStatus       `json:"overall_status"`
	DNSHealth     *DiagnosticResult  `json:"dns_health"`
	ConnHealth    *DiagnosticResult  `json:"connectivity_health"`
	BandwidthInfo *BandwidthResult   `json:"bandwidth_info"`
	ProxyInfo     *ProxyInfo         `json:"proxy_info"`
	Results       []DiagnosticResult `json:"results"`
	TestDuration  time.Duration      `json:"test_duration"`
}

NetworkHealth represents overall network health status.

type ProxyInfo

type ProxyInfo struct {
	Detected       bool              `json:"detected"`
	Type           ProxyType         `json:"type"`
	Address        string            `json:"address"`
	Port           int               `json:"port"`
	Authentication bool              `json:"authentication_required"`
	Environment    map[string]string `json:"environment_variables"`
	SystemProxy    bool              `json:"system_proxy"`
	Working        bool              `json:"working"`
	Details        map[string]string `json:"details"`
}

ProxyInfo represents proxy configuration information.

type ProxyType

type ProxyType int

ProxyType represents the type of proxy.

const (
	// ProxyHTTP represents HTTP proxy.
	ProxyHTTP ProxyType = iota

	// ProxyHTTPS represents HTTPS proxy.
	ProxyHTTPS

	// ProxySOCKS4 represents SOCKS4 proxy.
	ProxySOCKS4

	// ProxySOCKS5 represents SOCKS5 proxy.
	ProxySOCKS5

	// ProxyUnknown represents unknown proxy type.
	ProxyUnknown
)

func (ProxyType) String

func (pt ProxyType) String() string

String returns the string representation of ProxyType.

Jump to

Keyboard shortcuts

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