Documentation
¶
Overview ¶
An Economic ProxyPool Implement for ZhimaHTTP (http://h.zhimaruanjian.com/)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // ApiAddr is the zhima api http address ApiAddr string // BackUpCap is the backup proxy size limit, all backup proxy is costless until they become active one. BackUpCap int // ActiveCap is the active proxy size limit, all active proxy is paid already. ActiveCap int // ClearTime is the duration before the backup proxy cleared. ClearTime time.Duration // TimLimit is the proxy expire time, depend on your plan. TimeLimit time.Duration }
Config is the config for ZhimaProxyPool
type FilePersister ¶
type FilePersister struct {
FilePath string
}
FilePersister is a file based persister
func NewFilePersister ¶
func NewFilePersister(path string) *FilePersister
NewFilePersister return a FilePersister instance
func (*FilePersister) Load ¶
func (f *FilePersister) Load() ([]*Proxy, error)
Load []*Proxy from the file
func (*FilePersister) Save ¶
func (f *FilePersister) Save(proxies []*Proxy) error
Save the proxy to file with json format
type NilPersister ¶
type NilPersister struct{}
NilPersister is a nil persister, save nothing and load nothing
func NewNilPersister ¶
func NewNilPersister() *NilPersister
NewNilPersister return a NilPersister instance
type Persister ¶
Persister define a persister interface. It saves and loads the active proxy, or you will load new proxy every time you restart, which is not Economic.
type Proxy ¶
type Proxy struct { Ip string `json:"ip"` Port int `json:"port"` ExpireTimeString string `json:"expire_time"` }
func (*Proxy) ExpireTime ¶
ExpireTime() return a time.Time parsed from ExpireTimeString
func (*Proxy) ProxyString ¶
type ZhimaProxyPool ¶
ZhimaProxyPool is the proxy pool implement
func NewZhimaProxyPool ¶
func NewZhimaProxyPool(config *Config, persister Persister) *ZhimaProxyPool
NewZhimaProxyPool() return a ZhimaProxyPool instance
func (*ZhimaProxyPool) Clear ¶
func (pool *ZhimaProxyPool) Clear()
Clear() clear the backup proxy list
func (*ZhimaProxyPool) Delete ¶
func (pool *ZhimaProxyPool) Delete(proxy string) bool
Delete() remove a Proxy from active proxy list. Use it when you make sure the proxy is not usable. Abuse this may cost more.
func (*ZhimaProxyPool) Get ¶
func (pool *ZhimaProxyPool) Get() (*Proxy, error)
Get() try to get a usable Proxy. First, get a active proxy, if it has expired, replace it with a backup proxy and return the new proxy.
func (*ZhimaProxyPool) Start ¶
func (pool *ZhimaProxyPool) Start()
Start() start the background task
func (*ZhimaProxyPool) Stop ¶
func (pool *ZhimaProxyPool) Stop() error
Stop() call the persister.Save, this will not stop pool actually.