This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
proxies.go
135 lines (119 loc) · 2.56 KB
/
proxies.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package proxy
import (
"fmt"
"sort"
"strings"
"sync"
)
type ProxyList []Proxy
func (ps ProxyList) Len() int {
return len(ps)
}
func (ps ProxyList) TypeLen(t string) int {
l := 0
for _, p := range ps {
if p.TypeName() == t {
l++
}
}
return l
}
var sortType = make(map[string]int)
func init() {
sortType["ss"] = 1
sortType["ssr"] = 2
sortType["vmess"] = 3
sortType["trojan"] = 4
}
func (ps ProxyList) Less(i, j int) bool {
if ps[i].BaseInfo().Name == ps[j].BaseInfo().Name {
return sortType[ps[i].BaseInfo().Type] < sortType[ps[j].BaseInfo().Type]
} else {
return ps[i].BaseInfo().Name < ps[j].BaseInfo().Name
}
}
func (ps ProxyList) Swap(i, j int) {
ps[i], ps[j] = ps[j], ps[i]
}
func (ps ProxyList) Deduplication() ProxyList {
result := make(ProxyList, 0, len(ps))
temp := map[string]struct{}{}
for _, item := range ps {
if item != nil {
if _, ok := temp[item.Identifier()]; !ok {
temp[item.Identifier()] = struct{}{}
result = append(result, item)
}
}
}
return result
}
func (ps ProxyList) Sort() ProxyList {
sort.Sort(ps)
return ps
}
func (ps ProxyList) NameAddCounrty() ProxyList {
num := len(ps)
wg := &sync.WaitGroup{}
wg.Add(num)
for i := 0; i < num; i++ {
ii := i
go func() {
defer wg.Done()
_, country, err := geoIp.Find(ps[ii].BaseInfo().Server)
if err != nil {
country = "🏁 ZZ"
}
ps[ii].SetName(fmt.Sprintf("%s", country))
ps[ii].SetCountry(country)
//ps[ii].SetIP(ip)
}()
}
wg.Wait()
return ps
}
func (ps ProxyList) NameAddIndex() ProxyList {
num := len(ps)
for i := 0; i < num; i++ {
ps[i].SetName(fmt.Sprintf("%s_%+02v", ps[i].BaseInfo().Name, i+1))
}
return ps
}
func (ps ProxyList) NameReIndex() ProxyList {
num := len(ps)
for i := 0; i < num; i++ {
originName := ps[i].BaseInfo().Name
country := strings.SplitN(originName, "_", 2)[0]
ps[i].SetName(fmt.Sprintf("%s_%+02v", country, i+1))
}
return ps
}
func (ps ProxyList) NameAddTG() ProxyList {
num := len(ps)
for i := 0; i < num; i++ {
ps[i].SetName(fmt.Sprintf("%s %s", ps[i].BaseInfo().Name, "@peekfun"))
}
return ps
}
func Deduplication(src ProxyList) ProxyList {
result := make(ProxyList, 0, len(src))
temp := map[string]struct{}{}
for _, item := range src {
if item != nil {
if _, ok := temp[item.Identifier()]; !ok {
temp[item.Identifier()] = struct{}{}
result = append(result, item)
}
}
}
return result
}
func (ps ProxyList) Clone() ProxyList {
result := make(ProxyList, 0, len(ps))
for _, pp := range ps {
if pp != nil {
result = append(result, pp.Clone())
}
}
return result
}