feat: add type and default fields to rule group requests and update related logic
This commit is contained in:
committed by
Leif Draven
parent
40c24fbc85
commit
994cc4bebb
@@ -27,7 +27,7 @@ func NewAdapter(cfg *Config) *Adapter {
|
||||
// 转换服务器列表
|
||||
proxies := adapterProxies(cfg.Nodes)
|
||||
// 生成代理组
|
||||
proxyGroup, region := generateProxyGroup(proxies)
|
||||
proxyGroup, nodes := generateProxyGroup(proxies)
|
||||
|
||||
// 转换规则组
|
||||
g, r := adapterRules(cfg.Rules)
|
||||
@@ -35,7 +35,8 @@ func NewAdapter(cfg *Config) *Adapter {
|
||||
// 加入兜底节点
|
||||
for i, group := range g {
|
||||
if len(group.Proxies) == 0 {
|
||||
g[i].Proxies = append([]string{"DIRECT"}, region...)
|
||||
p := append([]string{"智能线路"}, nodes...)
|
||||
g[i].Proxies = append(p, "REJECT", "DIRECT")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ func NewAdapter(cfg *Config) *Adapter {
|
||||
Proxies: proxies,
|
||||
Group: proxyGroup,
|
||||
Rules: r,
|
||||
Region: region,
|
||||
Nodes: nodes,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ package proxy
|
||||
type Adapter struct {
|
||||
Proxies []Proxy
|
||||
Group []Group
|
||||
Rules []string
|
||||
Region []string
|
||||
Rules []string // rule
|
||||
Nodes []string // all node
|
||||
Default string // Default Node
|
||||
}
|
||||
|
||||
// Proxy represents a proxy server
|
||||
|
||||
@@ -121,7 +121,7 @@ func adapterTags(tags map[string][]*server.Server, group []proxy.Group) (proxyGr
|
||||
return group
|
||||
}
|
||||
|
||||
func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, region []string) {
|
||||
func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, nodes []string) {
|
||||
// 设置手动选择分组
|
||||
proxyGroup = append(proxyGroup, []proxy.Group{
|
||||
{
|
||||
@@ -139,17 +139,13 @@ func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, region
|
||||
}...)
|
||||
|
||||
for _, node := range servers {
|
||||
if node.Country != "" {
|
||||
proxyGroup = addProxyToGroup(node.Name, node.Country, proxyGroup)
|
||||
region = append(region, node.Country)
|
||||
|
||||
proxyGroup = addProxyToGroup(node.Country, "智能线路", proxyGroup)
|
||||
}
|
||||
|
||||
proxyGroup = addProxyToGroup(node.Name, "智能线路", proxyGroup)
|
||||
proxyGroup = addProxyToGroup(node.Name, "手动选择", proxyGroup)
|
||||
nodes = append(nodes, node.Name)
|
||||
}
|
||||
|
||||
proxyGroup = addProxyToGroup("DIRECT", "手动选择", proxyGroup)
|
||||
return proxyGroup, tool.RemoveDuplicateElements(region...)
|
||||
return proxyGroup, tool.RemoveDuplicateElements(nodes...)
|
||||
}
|
||||
|
||||
func adapterProxies(servers []*server.Server) []proxy.Proxy {
|
||||
|
||||
Reference in New Issue
Block a user