fetch proxies from db every task & bump version

This commit is contained in:
zu1k
2020-09-06 09:17:50 +08:00
parent 864f8403ac
commit 679c6fa0d4
3 changed files with 20 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ import (
"github.com/zu1k/proxypool/pkg/provider"
)
const version = "v0.3.6"
const version = "v0.3.7"
var router *gin.Engine

View File

@@ -21,6 +21,7 @@ func CrawlGo() {
go g.Get2Chan(pc, wg)
}
proxies := cache.GetProxies("allproxies")
proxies = append(proxies, database.GetAllProxies()...)
go func() {
wg.Wait()
close(pc)

View File

@@ -1,6 +1,7 @@
package database
import (
"github.com/zu1k/proxypool/pkg/getter"
"github.com/zu1k/proxypool/pkg/proxy"
"gorm.io/gorm"
)
@@ -48,3 +49,20 @@ func SaveProxyList(pl proxy.ProxyList) {
DB.Create(&proxies)
}
}
func GetAllProxies() (proxies proxy.ProxyList) {
proxies = make(proxy.ProxyList, 0)
if DB == nil {
return
}
proxiesDB := make([]Proxy, 0)
DB.Select("link").Find(&proxiesDB)
for _, proxyDB := range proxiesDB {
if proxiesDB != nil {
proxies = append(proxies, getter.String2Proxy(proxyDB.Link))
}
}
return
}