refactor(proxy): replace hardcoded group names with constants for better maintainability
This commit is contained in:
parent
97024dd1df
commit
8c4c7d0773
@ -13,6 +13,11 @@ import (
|
|||||||
"github.com/perfect-panel/server/pkg/adapter/v2rayn"
|
"github.com/perfect-panel/server/pkg/adapter/v2rayn"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
AutoSelect = "Auto - UrlTest"
|
||||||
|
Selection = "Selection"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Nodes []*server.Server
|
Nodes []*server.Server
|
||||||
Rules []*server.RuleGroup
|
Rules []*server.RuleGroup
|
||||||
@ -39,7 +44,7 @@ func NewAdapter(cfg *Config) *Adapter {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(group.Proxies) == 0 {
|
if len(group.Proxies) == 0 {
|
||||||
p := append([]string{"Auto Select", "Selection"}, nodes...)
|
p := append([]string{AutoSelect, Selection}, nodes...)
|
||||||
g[i].Proxies = append(p, "DIRECT")
|
g[i].Proxies = append(p, "DIRECT")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,7 +141,7 @@ func adapterTags(tags map[string][]*server.Server, group []proxy.Group) (proxyGr
|
|||||||
|
|
||||||
func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, nodes []string) {
|
func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, nodes []string) {
|
||||||
proxyGroup = append(proxyGroup, proxy.Group{
|
proxyGroup = append(proxyGroup, proxy.Group{
|
||||||
Name: "Auto Select",
|
Name: AutoSelect,
|
||||||
Type: proxy.GroupTypeURLTest,
|
Type: proxy.GroupTypeURLTest,
|
||||||
Proxies: make([]string, 0),
|
Proxies: make([]string, 0),
|
||||||
URL: "https://www.gstatic.com/generate_204",
|
URL: "https://www.gstatic.com/generate_204",
|
||||||
@ -150,14 +150,14 @@ func generateProxyGroup(servers []proxy.Proxy) (proxyGroup []proxy.Group, nodes
|
|||||||
|
|
||||||
// 设置手动选择分组
|
// 设置手动选择分组
|
||||||
proxyGroup = append(proxyGroup, proxy.Group{
|
proxyGroup = append(proxyGroup, proxy.Group{
|
||||||
Name: "Selection",
|
Name: Selection,
|
||||||
Type: proxy.GroupTypeSelect,
|
Type: proxy.GroupTypeSelect,
|
||||||
Proxies: []string{"Auto Select"},
|
Proxies: []string{AutoSelect},
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, node := range servers {
|
for _, node := range servers {
|
||||||
proxyGroup = addProxyToGroup(node.Name, "Auto Select", proxyGroup)
|
proxyGroup = addProxyToGroup(node.Name, AutoSelect, proxyGroup)
|
||||||
proxyGroup = addProxyToGroup(node.Name, "Selection", proxyGroup)
|
proxyGroup = addProxyToGroup(node.Name, Selection, proxyGroup)
|
||||||
nodes = append(nodes, node.Name)
|
nodes = append(nodes, node.Name)
|
||||||
}
|
}
|
||||||
return proxyGroup, tool.RemoveDuplicateElements(nodes...)
|
return proxyGroup, tool.RemoveDuplicateElements(nodes...)
|
||||||
@ -258,11 +258,11 @@ func SortGroups(groups []proxy.Group, defaultName string) []proxy.Group {
|
|||||||
group.Proxies = tool.RemoveStringElement(group.Proxies, defaultName, "REJECT")
|
group.Proxies = tool.RemoveStringElement(group.Proxies, defaultName, "REJECT")
|
||||||
sortedGroups = append([]proxy.Group{group}, sortedGroups...)
|
sortedGroups = append([]proxy.Group{group}, sortedGroups...)
|
||||||
continue
|
continue
|
||||||
} else if group.Name == "Selection" {
|
} else if group.Name == Selection {
|
||||||
group.Proxies = tool.RemoveStringElement(group.Proxies, defaultName)
|
group.Proxies = tool.RemoveStringElement(group.Proxies, defaultName)
|
||||||
selectedGroup = group
|
selectedGroup = group
|
||||||
continue
|
continue
|
||||||
} else if group.Name == "Auto Select" {
|
} else if group.Name == AutoSelect {
|
||||||
group.Proxies = tool.RemoveStringElement(group.Proxies, defaultName, group.Name)
|
group.Proxies = tool.RemoveStringElement(group.Proxies, defaultName, group.Name)
|
||||||
sortedGroups = append([]proxy.Group{group}, sortedGroups...)
|
sortedGroups = append([]proxy.Group{group}, sortedGroups...)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user