proxy

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package proxy parses proxy list files and hands proxies out to workers.

It is the modernized replacement for solar2-core's proxies package: Parse now returns descriptive errors (the old one returned errors.New("")) and accepts every common list format instead of just two.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(p Proxy, timeout time.Duration) error

Check verifies the proxy can reach the internet by fetching ip-api.com through it. Returns nil on success. This makes an outbound request and is intentionally kept out of Parse/Pool so parsing stays pure; call it explicitly when you want a liveness gate.

Types

type Pool

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

Pool hands proxies out to workers. Unlike input.Queue it never empties: Next round-robins forever and Random samples with replacement, which matches how proxies are actually used (rotate across many attempts). All methods are safe for concurrent use.

func LoadPool

func LoadPool(path string) (*Pool, error)

LoadPool parses a proxy list file into a Pool.

func NewPool

func NewPool(proxies []Proxy) *Pool

NewPool builds a Pool from an already-parsed slice.

func (*Pool) Len

func (p *Pool) Len() int

Len returns the number of proxies in the pool.

func (*Pool) Next

func (p *Pool) Next() (Proxy, bool)

Next returns the next proxy round-robin, wrapping around at the end. The bool is false only when the pool is empty.

func (*Pool) Random

func (p *Pool) Random() (Proxy, bool)

Random returns a uniformly random proxy (with replacement). The bool is false only when the pool is empty.

type Proxy

type Proxy struct {
	Scheme   string
	Host     string
	Port     int
	Username string
	Password string
}

Proxy is a single parsed proxy endpoint. Username/Password are empty for unauthenticated proxies. Scheme is "" when the source line carried no scheme (host:port[:user:pass] shorthand).

func Parse

func Parse(s string) (Proxy, error)

Parse accepts the common proxy list formats and returns a descriptive error on failure:

host:port
host:port:user:pass
user:pass@host:port
host:port@user:pass
scheme://host:port
scheme://user:pass@host:port

func ParseFile

func ParseFile(path string) ([]Proxy, error)

ParseFile reads a proxy list file and parses its non-empty lines.

func ParseLines

func ParseLines(lines []string) []Proxy

ParseLines parses each line, silently skipping ones that don't parse. Use Parse directly when you want to know why a line was rejected.

func (Proxy) Addr

func (p Proxy) Addr() string

Addr returns "host:port".

func (Proxy) HasAuth

func (p Proxy) HasAuth() bool

HasAuth reports whether the proxy carries credentials.

func (Proxy) URL

func (p Proxy) URL() string

URL renders the proxy as a scheme://[user:pass@]host:port URL. When the source carried no scheme, http is assumed.

Jump to

Keyboard shortcuts

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