Documentation
¶
Index ¶
- Variables
- func ApplyFilters(proxies []providers.Proxy, filters []Filter) []providers.Proxy
- func FreezeProvider(providerName string, timeout time.Duration) providers.Provider
- func InitLog(l *logrus.Logger)
- type ComplexPool
- func (pool *ComplexPool) ApplyCache() error
- func (pool *ComplexPool) Fetch() error
- func (pool *ComplexPool) FetchFallback() error
- func (pool *ComplexPool) Filter(filters ...Filter)
- func (pool *ComplexPool) Load() error
- func (pool *ComplexPool) New() (Proxy, error)
- func (pool *ComplexPool) NewFromCountries(countries []string) (Proxy, error)
- func (pool *ComplexPool) Option(opts ...Option) (err error)
- func (pool *ComplexPool) Random() (Proxy, error)
- func (pool *ComplexPool) SetTimeout(timeout time.Duration)
- func (pool *ComplexPool) SizeAll() int
- func (pool *ComplexPool) SizeUnused() int
- type Filter
- type Option
- func OptionAddFilter(filter Filter) Option
- func OptionAddFilters(filters ...Filter) Option
- func OptionFallbackToBackupProviders(setting bool) Option
- func OptionFallbackToCached(setting bool) Option
- func OptionReloadWhenEmpty(setting bool) Option
- func UseFallbackProvider(provider Provider) Option
- func UseFallbackProviders(givenProviders ...Provider) Option
- func UseProvider(provider Provider) Option
- func UseProviders(givenProviders ...Provider) Option
- type Pool
- type Provider
- type Proxy
- func (p *Proxy) AsHTTPClient() (*http.Client, error)
- func (p *Proxy) AsHTTPSClient() (*http.Client, error)
- func (p *Proxy) AsSOCKS4Client() (*http.Client, error)
- func (p *Proxy) AsSOCKS5Client() (*http.Client, error)
- func (p *Proxy) CheckConnection() bool
- func (p *Proxy) CheckSpeed(timeout time.Duration) bool
- func (p *Proxy) Client() (*http.Client, error)
- func (p *Proxy) PrettyPrint()
- type SimplePool
- func (pool *SimplePool) Filter(filters ...Filter)
- func (pool *SimplePool) Load() error
- func (pool *SimplePool) New() (Proxy, error)
- func (pool *SimplePool) Random() (Proxy, error)
- func (pool *SimplePool) SetTimeout(timeout time.Duration)
- func (pool *SimplePool) SizeAll() int
- func (pool *SimplePool) SizeUnused() int
Constants ¶
This section is empty.
Variables ¶
var FreeProxyLists = Provider{"FreeProxyLists", providers.FreeProxyLists}
FreeProxyLists defines the 'FreeProxyLists' provider.
var GetProxyList = Provider{"GetProxyList", providers.GetProxyList}
GetProxyList defines the 'GetProxyList' provider.
var Providers = map[string]Provider{ "FreeProxyLists": FreeProxyLists, "ProxyScrape": ProxyScrape, "GetProxyList": GetProxyList, "Static": Static, }
Providers is a global variable which allows translation between the names of providers and the provider functions themselves.
var ProxyScrape = Provider{"ProxyScrape", providers.ProxyScrape}
ProxyScrape defines the 'ProxyScrape' provider.
var Static = Provider{"Static", providers.Static}
Static defines the 'Static' provider.
Functions ¶
func ApplyFilters ¶
ApplyFilters will apply filters to a list of proxies, and will return a new proxy list.
func FreezeProvider ¶
FreezeProvider will gather proxies from the provider given one last time and then use those instead of new ones.
Types ¶
type ComplexPool ¶
type ComplexPool struct { Config struct { FallbackToBackupProviders bool FallbackToCached bool ReloadWhenEmpty bool } All *providers.Set Unused *providers.Set CacheAvailable bool CacheAll *providers.Set CacheUnused *providers.Set // contains filtered or unexported fields }
ComplexPool is an implementation of a pool with lots of extra settings, including filtering and ensuring the pool always has proxies to provide.
func NewComplexPool ¶
func NewComplexPool(opts ...Option) *ComplexPool
NewComplexPool creates a new complex pool from the options given and using defaults if options aren't provided.
func NewPool ¶
func NewPool(opts ...Option) *ComplexPool
NewPool creates a new complex pool from the options given and using defaults if options aren't provided. It's an alias for NewComplexPool.
func (*ComplexPool) ApplyCache ¶
func (pool *ComplexPool) ApplyCache() error
ApplyCache will revert the pool to the previous cache.
func (*ComplexPool) Fetch ¶
func (pool *ComplexPool) Fetch() error
Fetch fetches the proxies from it's internal providers and stores them.
func (*ComplexPool) FetchFallback ¶
func (pool *ComplexPool) FetchFallback() error
FetchFallback fetches the proxies from it's fallback providers and stores them.
func (*ComplexPool) Filter ¶
func (pool *ComplexPool) Filter(filters ...Filter)
Filter applies the filter to the proxies inside the pool.
func (*ComplexPool) Load ¶
func (pool *ComplexPool) Load() error
Load will fetch the proxies like a call to Fetch(), but, depending on options, it will fallback to a proxy cache or use the fallback providers.
func (*ComplexPool) New ¶
func (pool *ComplexPool) New() (Proxy, error)
New fetches a new, unused proxy. Depending on options, it will attempt to reload the proxy pool if there are no proxies left inside the pool.
func (*ComplexPool) NewFromCountries ¶
func (pool *ComplexPool) NewFromCountries(countries []string) (Proxy, error)
NewFromCountries gets a new, unused proxy whose location is one of the countries specified.. Depending on options, it will attempt to reload the proxy pool if there are no proxies left inside the pool.
func (*ComplexPool) Option ¶
func (pool *ComplexPool) Option(opts ...Option) (err error)
Option sets the pool options specified.
func (*ComplexPool) Random ¶
func (pool *ComplexPool) Random() (Proxy, error)
Random fetches a random proxy. It doesn't care if the proxy has been used already. It still marks a proxy as used.
func (*ComplexPool) SetTimeout ¶
func (pool *ComplexPool) SetTimeout(timeout time.Duration)
SetTimeout sets a timeout for the provider. By default, it is set to 15s by NewSimplePool.
func (*ComplexPool) SizeAll ¶
func (pool *ComplexPool) SizeAll() int
SizeAll finds the amount of proxies that are currently loaded, used or unused.
func (*ComplexPool) SizeUnused ¶
func (pool *ComplexPool) SizeUnused() int
SizeUnused finds the amount of proxies that are currently unused.
type Filter ¶
Filter is a function that will either allow or not allow a proxy. A filter returns true if a proxy "succeeds", and false if it is not allowed.
func FilterAllowCountries ¶
FilterAllowCountries creates a filter that only allows the countries specified. The countries provided must be in the ISO Alpha-2 format (GB, US, etc...)
func FilterDisallowCountries ¶
FilterDisallowCountries creates a filter that does not let countries from the list to be present.
func FilterProxyConnection ¶
func FilterProxyConnection() Filter
FilterProxyConnection creates a filter that will only disallow a proxy if it is not working. A timeout of 10 seconds is applied, but if a proxy does timeout it is not marked as not working.
func FilterProxySpeed ¶
FilterProxySpeed creates a filter that only allows proxies if they can make a successful request in a given timeframe.
func FilterProxyTypes ¶
FilterProxyTypes creates a filter that only allows specific types of proxies, such as HTTP or SOCKS5.
type Option ¶
type Option func(*ComplexPool) error
Option is an option that can be provided to configure a complex pool. See https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html for more info
func OptionAddFilter ¶
OptionAddFilter adds a single filter to the pool.
func OptionAddFilters ¶
OptionAddFilters adds a list of filters to the pool
func OptionFallbackToBackupProviders ¶
OptionFallbackToBackupProviders sets the option to use the fallback providers if there is an error during loading.
func OptionFallbackToCached ¶
OptionFallbackToCached sets the option to use cached proxies when there is an error during loading.
func OptionReloadWhenEmpty ¶
OptionReloadWhenEmpty sets the option to attempt to load new proxies into the pool if there are no proxies left in the pool on a call to .Random() or .New()
func UseFallbackProvider ¶
UseFallbackProvider adds a provider that will only be used if the other providers fail. If the provider name is invalid, it will panic.
func UseFallbackProviders ¶
UseFallbackProviders adds providers that will only be used if the other providers do not work. If any of the provider names are invalid, it will panic.
func UseProvider ¶
UseProvider will add a provider to pool. If the provider name is invalid, it will panic.
func UseProviders ¶
UseProviders will adds providers to the pool. If any of the provider names is invalid, it will panic.
type Pool ¶
type Pool interface { Load() error Filter() error SizeAll() int SizeUnused() int New() (Proxy, error) Random() (Proxy, error) }
Pool represents a collection/store of proxies.
type Provider ¶
Provider is a wrapper around the providers.Provider type, giving information about the provider along with the actual provider function itself.
func GetProvider ¶
GetProvider gets the provider by name.
func GetProviders ¶
GetProviders gets multiple providers by name.
func MultiProvider ¶
MultiProvider creates a new hybrid-provider from a set of existing ones. It will fetch all the proxies from all providers asynchronously.
type Proxy ¶
type Proxy struct { URL *url.URL Provider string Country string // contains filtered or unexported fields }
Proxy holds information about a proxy. It is like providers.Proxy, but it contains more methods.
func (*Proxy) AsHTTPClient ¶
AsHTTPClient will return the proxy as a http.Client struct. It panics if the proxy's type is not HTTP.
func (*Proxy) AsHTTPSClient ¶
AsHTTPSClient will return the proxy as a http.Client struct. It panics if the proxy's type is not HTTPS.
func (*Proxy) AsSOCKS4Client ¶
AsSOCKS4Client will return the proxy as a http.Client struct. It panics if the proxy's type is not SOCKS4.
func (*Proxy) AsSOCKS5Client ¶
AsSOCKS5Client will return the proxy as a http.Client struct. It panics if the proxy's type is not SOCKS5.
func (*Proxy) CheckConnection ¶
CheckConnection checks that a connection to a proxy can be formed. It will still mark a proxy as successful even if it times out. If you want to filter proxies that timeout, use CheckSpeed(10 * time.Second), which is equivalent.
func (*Proxy) CheckSpeed ¶
CheckSpeed checks that a connection to proxy can be formed. It accepts a timeout, and will mark a proxy as unavailable if it doesn't respond within that time.
func (*Proxy) PrettyPrint ¶
func (p *Proxy) PrettyPrint()
PrettyPrint prints some information in a nicely-formatted way.
type SimplePool ¶
type SimplePool struct { All *providers.Set Unused *providers.Set // contains filtered or unexported fields }
SimplePool is an implementation of a pool without much added functionality. It is a simple wrapper for a provider.
func NewSimplePool ¶
func NewSimplePool(givenProviders ...Provider) *SimplePool
NewSimplePool returns a new a new SimplePool struct.
func (*SimplePool) Filter ¶
func (pool *SimplePool) Filter(filters ...Filter)
Filter applies the filter to the proxies inside the pool.
func (*SimplePool) Load ¶
func (pool *SimplePool) Load() error
Load fetches the proxies from it's internal provider and stores them.
func (*SimplePool) New ¶
func (pool *SimplePool) New() (Proxy, error)
New fetches a new, unused proxy. It returns an error if there are no unused proxies left.
func (*SimplePool) Random ¶
func (pool *SimplePool) Random() (Proxy, error)
Random fetches a random proxy. It doesn't care if the proxy has been used already. It still marks a proxy as used.
func (*SimplePool) SetTimeout ¶
func (pool *SimplePool) SetTimeout(timeout time.Duration)
SetTimeout sets a timeout for the provider. By default, it is set to 15s by NewSimplePool.
func (*SimplePool) SizeAll ¶
func (pool *SimplePool) SizeAll() int
SizeAll finds the amount of proxies that are currently loaded, used or unused.
func (*SimplePool) SizeUnused ¶
func (pool *SimplePool) SizeUnused() int
SizeUnused finds the amount of proxies that are currently unused.