go get github.com/diinvoke/proxy-pool
go mod tidy
import (
"github.com/diinvoke/proxy-pool"
"github.com/diinvoke/proxy-pool/model"
)
func Random() *model.IP {
rangeIp := proxypool.Range("https")
// if need check
// proxyUrl := proxyIp.Protocol + "://" + proxyIp.Address + ":" + proxyIp.Port
// if !proxypool.Check(proxyUrl) {
// return Random()
// }
return rangeIp
}
func Check(proxy string) bool {
return proxypool.Check(proxy)
}
import (
"github.com/diinvoke/proxy-pool/storage"
)
type DemoSpider struct{}
func NewDemoSpider() Spider {
return &DemoSpider{}
}
// implements Spider interface
var _ Spider = &DemoSpider{}
func (demo *DemoSpider) Do() error {
// do something
}
import "github.com/diinvoke/proxy-pool/spider"
spiders := []spider.ISpider{
spider.NewIP181(store),
spider.NewDemoSpider()
}
import (
"github.com/diinvoke/proxy-pool/model"
)
type DemoStorage struct{}
// implements Storage interface
var _ IStorage = &DemoStorage()
func NewDemoStorage() IStorage {
return &DemoStorage{}
}
func (d *DemoStorage) Save(ip *model.IP) error {
// do something
}
func (d *DemoStorage) Del(ip *model.IP) bool {
// do something
}
func (d *DemoStorage) Random(protocol model.Protocol) (ip *model.IP, err error) {
// do something
}
func (d *DemoStorage) Close() error {
// do something
}
func init() {
store = storage.NewDemoStorage()
initProxyPool(store)
go autoLoad()
}