proxy

package
v0.0.0-...-54d95db Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTransport

func NewTransport(config ProxyConfig) (*http.Transport, error)

NewTransport creates a new http.Transport based on the provided ProxyConfig.

Types

type HTTPProxy

type HTTPProxy struct {
	Address  string
	Username string
	Password string

	Timeout time.Duration
}

HTTPProxy represents an HTTP proxy configuration.

func (*HTTPProxy) Apply

func (hp *HTTPProxy) Apply(transport *http.Transport) error

Apply configures the transport to use an HTTP proxy.

type NoProxy

type NoProxy struct {
}

NoProxy represents a direct connection without any proxy.

func (*NoProxy) Apply

func (np *NoProxy) Apply(transport *http.Transport) error

Apply configures the transport for a direct connection.

type Proxy

type Proxy interface {
	// Apply configures the http.Transport with proxy settings.
	Apply(*http.Transport) error
}

Proxy defines the interface for different proxy types.

func NewProxy

func NewProxy(config ProxyConfig) (Proxy, error)

NewProxy creates a Proxy implementation based on the provided ProxyConfig.

type ProxyConfig

type ProxyConfig struct {
	Type              ProxyType
	Address           string        // e.g., "127.0.0.1:8080" for HTTP or "127.0.0.1:1080" for SOCKS5
	Username          string        // Optional: For proxies that require authentication
	Password          string        // Optional: For proxies that require authentication
	Timeout           time.Duration // Timeout for connections
	TLSConfig         *tls.Config   // Optional: For custom TLS settings
	DisableKeepAlives bool          // Optional: To disable HTTP keep-alives
	CustomDialer      proxy.Dialer  // Optional: Allows injecting a custom dialer (useful for testing)
}

ProxyConfig holds the configuration for the proxy.// ProxyConfig holds the configuration for the proxy.

type ProxyType

type ProxyType string

ProxyType represents the type of proxy to use.

const (
	ProxyTypeNone   ProxyType = "NONE"
	ProxyTypeHTTP   ProxyType = "HTTP"
	ProxyTypeSOCKS5 ProxyType = "SOCKS5"
)

type SOCKS5Proxy

type SOCKS5Proxy struct {
	Address  string
	Username string
	Password string
	Dialer   proxy.Dialer // Allows injecting a custom dialer, useful for testing.

	Timeout time.Duration // This is your custom timeout for the SOCKS5 connection
}

SOCKS5Proxy represents a SOCKS5 proxy configuration.

func (*SOCKS5Proxy) Apply

func (sp *SOCKS5Proxy) Apply(transport *http.Transport) error

Apply configures the transport to use a SOCKS5 proxy.

Jump to

Keyboard shortcuts

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