splite source from config
This commit is contained in:
@@ -115,7 +115,7 @@
|
|||||||
<p>可用节点数量:{{ .useful_proxies_count }}</p>
|
<p>可用节点数量:{{ .useful_proxies_count }}</p>
|
||||||
<p>最后更新时间:{{ .last_crawl_time }}</p>
|
<p>最后更新时间:{{ .last_crawl_time }}</p>
|
||||||
<br>
|
<br>
|
||||||
<h5><a href="/clash">Clash</a></h5>
|
<h4><a href="/clash">Clash</a></h4>
|
||||||
<p>Clash配置文件:https://{{ .domain }}/clash/config <a
|
<p>Clash配置文件:https://{{ .domain }}/clash/config <a
|
||||||
href="clash://install-config?url=https://{{ .domain }}/clash/config">一键导入</a></p>
|
href="clash://install-config?url=https://{{ .domain }}/clash/config">一键导入</a></p>
|
||||||
<p>Clash proxy-provider(Shadowrocket添加订阅方式可用):<a href="https://{{ .domain }}/clash/proxies">https://{{ .domain }}/clash/proxies</a>
|
<p>Clash proxy-provider(Shadowrocket添加订阅方式可用):<a href="https://{{ .domain }}/clash/proxies">https://{{ .domain }}/clash/proxies</a>
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
<p>筛选代理类型:https://{{ .domain }}/clash/proxies?type=ss,ssr,vmess</p>
|
<p>筛选代理类型:https://{{ .domain }}/clash/proxies?type=ss,ssr,vmess</p>
|
||||||
<p>筛选国家:https://{{ .domain }}/clash/proxies?c=HK,TW,US</p>
|
<p>筛选国家:https://{{ .domain }}/clash/proxies?c=HK,TW,US</p>
|
||||||
<br>
|
<br>
|
||||||
<h5><a href="/surge">Surge</a></h5>
|
<h4><a href="/surge">Surge</a></h4>
|
||||||
<p>Surge配置文件:https://{{ .domain }}/surge/config <a
|
<p>Surge配置文件:https://{{ .domain }}/surge/config <a
|
||||||
href="surge3:///install-config?url=https://{{ .domain }}/surge/config">一键导入</a></p>
|
href="surge3:///install-config?url=https://{{ .domain }}/surge/config">一键导入</a></p>
|
||||||
<p>Surge proxy list:<a href="https://{{ .domain }}/surge/proxies">https://{{ .domain }}/surge/proxies</a>
|
<p>Surge proxy list:<a href="https://{{ .domain }}/surge/proxies">https://{{ .domain }}/surge/proxies</a>
|
||||||
|
|||||||
@@ -12,16 +12,11 @@ import (
|
|||||||
|
|
||||||
var configFilePath = "config.yaml"
|
var configFilePath = "config.yaml"
|
||||||
|
|
||||||
type Source struct {
|
|
||||||
Type string `json:"type" yaml:"type"`
|
|
||||||
Options tool.Options `json:"options" yaml:"options"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConfigOptions struct {
|
type ConfigOptions struct {
|
||||||
Domain string `json:"domain" yaml:"domain"`
|
Domain string `json:"domain" yaml:"domain"`
|
||||||
CFEmail string `json:"cf_email" yaml:"cf_email"`
|
CFEmail string `json:"cf_email" yaml:"cf_email"`
|
||||||
CFKey string `json:"cf_key" yaml:"cf_key"`
|
CFKey string `json:"cf_key" yaml:"cf_key"`
|
||||||
Sources []Source `json:"sources" yaml:"sources"`
|
SourceFiles []string `json:"source-files" yaml:"source-files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config 配置
|
// Config 配置
|
||||||
@@ -34,7 +29,7 @@ func Parse(path string) error {
|
|||||||
} else {
|
} else {
|
||||||
configFilePath = path
|
configFilePath = path
|
||||||
}
|
}
|
||||||
fileData, err := readConfigFile(path)
|
fileData, err := ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -59,7 +54,7 @@ func Parse(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 从本地文件或者http链接读取配置文件内容
|
// 从本地文件或者http链接读取配置文件内容
|
||||||
func readConfigFile(path string) ([]byte, error) {
|
func ReadFile(path string) ([]byte, error) {
|
||||||
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
|
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
|
||||||
resp, err := tool.GetHttpClient().Get(path)
|
resp, err := tool.GetHttpClient().Get(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,33 +1,6 @@
|
|||||||
domain: proxy.tgbot.co
|
domain: example.com
|
||||||
cf_email: ""
|
cf_email: ""
|
||||||
cf_key: ""
|
cf_key: ""
|
||||||
sources:
|
sources:
|
||||||
# 模糊抓取订阅链接
|
- ./source.yaml
|
||||||
- type: webfuzzsub
|
- https://example.com/source.yaml
|
||||||
options:
|
|
||||||
url: https://raw.githubusercontent.com/du5/free/master/sub.list
|
|
||||||
|
|
||||||
# 订阅链接
|
|
||||||
- type: subscribe
|
|
||||||
options:
|
|
||||||
url: https://raw.githubusercontent.com/ssrsub/ssr/master/v2ray
|
|
||||||
|
|
||||||
# 网页模糊抓取
|
|
||||||
- type: webfuzz
|
|
||||||
options:
|
|
||||||
url: https://merlinblog.xyz/wiki/freess.html
|
|
||||||
|
|
||||||
# tg频道抓取
|
|
||||||
- type: tgchannel
|
|
||||||
options:
|
|
||||||
channel: ssrList
|
|
||||||
num: 200
|
|
||||||
|
|
||||||
# 翻墙党论坛抓取
|
|
||||||
- type: web-fanqiangdang-rss
|
|
||||||
options:
|
|
||||||
url: https://fanqiangdang.com/forum.php?mod=rss&fid=50&auth=0
|
|
||||||
|
|
||||||
# 某个网站抓取
|
|
||||||
- type: web-freessrxyz
|
|
||||||
options:
|
|
||||||
8
config/source.go
Normal file
8
config/source.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import "github.com/zu1k/proxypool/pkg/tool"
|
||||||
|
|
||||||
|
type Source struct {
|
||||||
|
Type string `json:"type" yaml:"type"`
|
||||||
|
Options tool.Options `json:"options" yaml:"options"`
|
||||||
|
}
|
||||||
30
config/source.yaml
Normal file
30
config/source.yaml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
sources:
|
||||||
|
# 模糊抓取订阅链接
|
||||||
|
- type: webfuzzsub
|
||||||
|
options:
|
||||||
|
url: https://raw.githubusercontent.com/du5/free/master/sub.list
|
||||||
|
|
||||||
|
# 订阅链接
|
||||||
|
- type: subscribe
|
||||||
|
options:
|
||||||
|
url: https://raw.githubusercontent.com/ssrsub/ssr/master/v2ray
|
||||||
|
|
||||||
|
# 网页模糊抓取
|
||||||
|
- type: webfuzz
|
||||||
|
options:
|
||||||
|
url: https://merlinblog.xyz/wiki/freess.html
|
||||||
|
|
||||||
|
# tg频道抓取
|
||||||
|
- type: tgchannel
|
||||||
|
options:
|
||||||
|
channel: ssrList
|
||||||
|
num: 200
|
||||||
|
|
||||||
|
# 翻墙党论坛抓取
|
||||||
|
- type: web-fanqiangdang-rss
|
||||||
|
options:
|
||||||
|
url: https://fanqiangdang.com/forum.php?mod=rss&fid=50&auth=0
|
||||||
|
|
||||||
|
# 某个网站抓取
|
||||||
|
- type: web-freessrxyz
|
||||||
|
options:
|
||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ghodss/yaml"
|
||||||
|
|
||||||
"github.com/zu1k/proxypool/config"
|
"github.com/zu1k/proxypool/config"
|
||||||
"github.com/zu1k/proxypool/pkg/getter"
|
"github.com/zu1k/proxypool/pkg/getter"
|
||||||
)
|
)
|
||||||
@@ -15,7 +17,7 @@ func InitConfigAndGetters(path string) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s := config.Config.Sources; len(s) == 0 {
|
if s := config.Config.SourceFiles; len(s) == 0 {
|
||||||
return errors.New("no sources")
|
return errors.New("no sources")
|
||||||
} else {
|
} else {
|
||||||
initGetters(s)
|
initGetters(s)
|
||||||
@@ -23,9 +25,20 @@ func InitConfigAndGetters(path string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func initGetters(sources []config.Source) {
|
func initGetters(sourceFiles []string) {
|
||||||
Getters = make([]getter.Getter, 0)
|
Getters = make([]getter.Getter, 0)
|
||||||
for _, source := range sources {
|
for _, path := range sourceFiles {
|
||||||
|
source := config.Source{}
|
||||||
|
data, err := config.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("Init SourceFile Error: %s\n", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = yaml.Unmarshal(data, &source)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("Init SourceFile Error: %s\n", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
g, err := getter.NewGetter(source.Type, source.Options)
|
g, err := getter.NewGetter(source.Type, source.Options)
|
||||||
if err == nil && g != nil {
|
if err == nil && g != nil {
|
||||||
Getters = append(Getters, g)
|
Getters = append(Getters, g)
|
||||||
|
|||||||
Reference in New Issue
Block a user