goPryPool

package module
v1.0.1-0...-bd3aba7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

#安装

go get -u github.com/zqjzqj/goPryPool

#暂只支持芝麻代理/黑洞代理

使用前添加IP白名单
//pool := OpenPool(&HdProxy{})
pool := OpenPool(&ZmProxy{})
pool.SetMaxOpen(2)

//该方法在无空闲代理的时候回阻塞 
//所以其余代理使用后需要及时释放或关闭
pry, err := pool.GetPry()
if err != nil {
    log.Fatal(err)
}

log.Println(pry.GetProxyUrl())

//释放代理 放回代理池
pry.Release()
pry.Close() 关闭代理 不在放回连接池
//更多方法请查看源代码

#自定义代理 实现接口

type Driver interface {
	CreateProxies(num int, pool *Pool) ([]*Proxy, error)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultExpireAdvance time.Duration = 0
View Source
var DefaultExpireAdvanceAsNotUse time.Duration = 0
View Source
var ErrMaxOpenCreatedPry = errors.New("已达到最大创建代理,无法创建新的代理")
View Source
var ErrPoolClosed = errors.New("代理池已关闭")
View Source
var ErrPryClosed = errors.New("对应代理已关闭")
View Source
var ErrPryExpired = errors.New("该代理已过期")
View Source
var ErrPutCreatedPry = errors.New("写入代理池失败")
View Source
var ErrWaitCreatedPry = errors.New("等待创建新的代理")
View Source
var ErrWaitPryTimeout = errors.New("等待获取代理超时")

Functions

This section is empty.

Types

type Driver

type Driver interface {
	CreateProxies(num int, pool *Pool) ([]*Proxy, error)
}

type HdProxy

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

func (*HdProxy) CreateProxies

func (hd *HdProxy) CreateProxies(num int, pool *Pool) ([]*Proxy, error)

设置芝麻代理的白名单IP才可用

type Pool

type Pool struct {
	IsAutoCloseExpiredPry bool

	MaxPryUseNum uint
	// contains filtered or unexported fields
}

func OpenPool

func OpenPool(apiDriver Driver) *Pool

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) CreateNewProxies

func (p *Pool) CreateNewProxies()

func (*Pool) GetDriver

func (p *Pool) GetDriver() Driver

func (Pool) GetFreePry

func (p Pool) GetFreePry() []*Proxy

func (*Pool) GetMaxOpen

func (p *Pool) GetMaxOpen() int

func (Pool) GetOpenNum

func (p Pool) GetOpenNum() int

func (*Pool) GetPry

func (p *Pool) GetPry() (*Proxy, error)

func (*Pool) PryIdleCleaner

func (p *Pool) PryIdleCleaner()

清理多余的空闲代理

func (*Pool) PutPry

func (p *Pool) PutPry(pry *Proxy) bool

func (*Pool) SetMaxIdle

func (p *Pool) SetMaxIdle(num int)

func (*Pool) SetMaxOpen

func (p *Pool) SetMaxOpen(num int)

func (*Pool) SetWaitPryTimeoutForGet

func (p *Pool) SetWaitPryTimeoutForGet(duration time.Duration)

type Proxies

type Proxies []*Proxy

func (Proxies) Len

func (ps Proxies) Len() int

Len()

func (Proxies) Less

func (ps Proxies) Less(i, j int) bool

Less(): 成绩将有低到高排序

func (Proxies) Swap

func (ps Proxies) Swap(i, j int)

Swap()

type Proxy

type Proxy struct {
	IsSocks5 bool

	MaxUseNum uint
	// contains filtered or unexported fields
}

func NewErrProxy

func NewErrProxy(err error) *Proxy

func NewProxy

func NewProxy(pool *Pool, ip string, port uint64, expire time.Time, isSSl bool, city string, isp string) *Proxy

func (*Proxy) AddTimeoutCount

func (pry *Proxy) AddTimeoutCount()

func (*Proxy) CancelListenAutoExpire

func (pry *Proxy) CancelListenAutoExpire()

func (*Proxy) Close

func (pry *Proxy) Close()

func (*Proxy) CreateListenAutoExpire

func (pry *Proxy) CreateListenAutoExpire()

func (Proxy) GetCity

func (pry Proxy) GetCity() string

func (*Proxy) GetExpire

func (pry *Proxy) GetExpire() time.Time

func (*Proxy) GetExpiredCh

func (pry *Proxy) GetExpiredCh() <-chan struct{}

func (Proxy) GetIpAddr

func (pry Proxy) GetIpAddr() string

func (Proxy) GetIsp

func (pry Proxy) GetIsp() string

func (Proxy) GetPoolDriverName

func (pry Proxy) GetPoolDriverName() string

func (Proxy) GetPort

func (pry Proxy) GetPort() uint64

func (*Proxy) GetProxyIpAddr

func (pry *Proxy) GetProxyIpAddr() string

func (*Proxy) GetProxyUrl

func (pry *Proxy) GetProxyUrl() string

func (*Proxy) GetTimeoutCount

func (pry *Proxy) GetTimeoutCount() uint8

func (*Proxy) GetTotalUseNum

func (pry *Proxy) GetTotalUseNum() uint

func (*Proxy) GetUseNum

func (pry *Proxy) GetUseNum() uint

func (*Proxy) IsClosed

func (pry *Proxy) IsClosed() bool

func (*Proxy) IsExpired

func (pry *Proxy) IsExpired() bool

当前时间+30s 超过这个时间就算过期 因为如果只差几秒过期的代理拿出来可能会运行不完一套程序

func (*Proxy) IsExpiredAndClose

func (pry *Proxy) IsExpiredAndClose() bool

func (Proxy) IsListenExpired

func (pry Proxy) IsListenExpired() bool

func (*Proxy) IsUse

func (pry *Proxy) IsUse() bool

func (*Proxy) Release

func (pry *Proxy) Release() bool

释放一个代理 在代理用完之后调用此方法 否则将会直接丢弃 会导致代理的重用率下降

func (*Proxy) SetDelayReleaseNum

func (pry *Proxy) SetDelayReleaseNum(num int)

func (*Proxy) SetExpiredAdvance

func (pry *Proxy) SetExpiredAdvance(t time.Duration)

func (*Proxy) SetExpiredAdvanceAsNotUse

func (pry *Proxy) SetExpiredAdvanceAsNotUse(t time.Duration)

func (*Proxy) SetUse

func (pry *Proxy) SetUse()

type ZmProxy

type ZmProxy struct {
}

func (*ZmProxy) CreateProxies

func (zm *ZmProxy) CreateProxies(num int, pool *Pool) ([]*Proxy, error)

设置芝麻代理的白名单IP才可用

Jump to

Keyboard shortcuts

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