fix 修复panic

This commit is contained in:
timerzz 2024-12-10 21:13:07 +08:00
parent bc08302d92
commit e06cad6bc5
4 changed files with 74 additions and 20 deletions

View File

@ -1,17 +1,51 @@
# 模糊抓取订阅链接
# clash格式订阅链接
#- type: clash
# options:
# url: https://raw.githubusercontent.com/aiboboxx/clashfree/refs/heads/main/clash.yml
#- type: clash
# options:
# url: https://ndQWjqRo.doggygo.top:8443/api/v1/client/3341e18dd5fe807b2777f60d24e77605?flag=clashmeta
# date-format: false
- type: clash
options:
url: https://raw.githubusercontent.com/aiboboxx/clashfree/refs/heads/main/clash.yml
- type: clash
options:
url: https://clashgithub.com/wp-content/uploads/rss/20060102.yml
date-format: true
- type: clash
options:
url: https://www.freeclashnode.com/uploads/2006/01/0-20060102.yaml
date-format: true
- type: clash
options:
url: https://www.freeclashnode.com/uploads/2006/01/1-20060102.yaml
date-format: true
- type: clash
options:
url: https://oneclash.githubrowcontent.com/2006/01/20060102.yaml
date-format: true
- type: clash
options:
url: https://raw.githubusercontent.com/ermaozi/get_subscribe/main/subscribe/clash.yml
- type: clash
options:
url: https://jif421.net/link/bLZIXBkdkIVpcFwT?clash=1
- type: clash
options:
url: http://wzm.api-node.shop/node/20060102-clash.yaml
date-format: true
- type: clash
options:
url: https://aPspT5j.doggygo.top:8443/api/v1/client/3341e18dd5fe807b2777f60d24e77605?flag=clashmeta
- type: subscribe
options:
url: https://proxy.v2gh.com/https://raw.githubusercontent.com/Pawdroid/Free-servers/main/sub
- type: subscribe
options:
url: https://s1.byte16.com/api/v1/client/subscribe?token=5a0e518c0fbfeb5ee5884215e076688f
- type: subscribe
options:
url: https://sub.cloudog.us.kg/api/v1/client/subscribe?token=aba7727a7e58c6d1d47ae5fb7d7e1d23&types=vless
- type: subscribe
options:
url: https://sub.kaolacloud.site/api/v1/client/subscribe?token=fa675c35ef99a4ec1211534af65ae1b3
url: https://sub.kaolacloud.site/api/v1/client/subscribe?token=fa675c35ef99a4ec1211534af65ae1b3

View File

@ -13,6 +13,7 @@ import (
clash_config "github.com/metacubex/mihomo/config"
"github.com/nitezs/sub2clash/api/handler"
"github.com/nitezs/sub2clash/config"
"github.com/nitezs/sub2clash/logger"
"github.com/nitezs/sub2clash/model"
"github.com/nitezs/sub2clash/validator"
"gopkg.in/yaml.v3"
@ -21,6 +22,7 @@ import (
func init() {
Register("subscribe", NewSubscribeGetter)
_ = config.LoadConfig()
logger.InitLogger("Warn")
_ = os.MkdirAll("./subs", 0755)
}

View File

@ -2,26 +2,37 @@ package proxy
import (
"context"
"sync"
"time"
"gitea.timerzz.com/kedaya_haitao/proxy-detector/pkg/getter"
healthcheck "gitea.timerzz.com/kedaya_haitao/proxy-detector/pkg/health-check"
"gitea.timerzz.com/kedaya_haitao/proxy-detector/pkg/proxy/structs"
"gitea.timerzz.com/kedaya_haitao/proxy-detector/pkg/worker"
log "github.com/sirupsen/logrus"
)
func CrawlProxies(ctx context.Context, getters []getter.Getter) {
var proxies []structs.Proxy
var proxies structs.Proxies
log.Infof("共%d个抓取源", len(getters))
for _, getter := range getters {
if ps := getter.Get(); len(ps) > 0 {
proxies = append(proxies, ps...)
var wg sync.WaitGroup
for _, gtr := range getters {
wg.Add(1)
err := worker.Pool.Submit(func() {
defer wg.Done()
if ps := gtr.Get(); len(ps) > 0 {
proxies.Add(ps)
}
})
if err != nil {
log.Errorln("添加并发任务失败: ", err)
}
}
log.Infof("Crawled %d proxies", len(proxies))
proxies = healthcheck.CleanBadProxies(ctx, proxies)
log.Infof("Health checked %d proxies", len(proxies))
structs.ProxiesList.Add(proxies)
wg.Wait()
log.Infof("Crawled %d proxies", proxies.Len())
proxyList := healthcheck.CleanBadProxies(ctx, proxies.Get())
log.Infof("Health checked %d proxies", proxyList)
structs.ProxiesList.Add(proxyList)
return
}

View File

@ -88,6 +88,13 @@ func (p *Proxies) Get() []Proxy {
return p.proxies
}
// 获取长度
func (p *Proxies) Len() int {
p.m.RLock()
defer p.m.RUnlock()
return len(p.proxies)
}
// 获取mapping列表
func (p *Proxies) Mapping() []map[string]any {
p.m.RLock()