Fix: typo
This commit is contained in:
@ -9,7 +9,7 @@ import (
|
||||
type Selector struct {
|
||||
name string
|
||||
selected C.Proxy
|
||||
proxys map[string]C.Proxy
|
||||
proxies map[string]C.Proxy
|
||||
}
|
||||
|
||||
func (s *Selector) Name() string {
|
||||
@ -30,14 +30,14 @@ func (s *Selector) Now() string {
|
||||
|
||||
func (s *Selector) All() []string {
|
||||
var all []string
|
||||
for k := range s.proxys {
|
||||
for k := range s.proxies {
|
||||
all = append(all, k)
|
||||
}
|
||||
return all
|
||||
}
|
||||
|
||||
func (s *Selector) Set(name string) error {
|
||||
proxy, exist := s.proxys[name]
|
||||
proxy, exist := s.proxies[name]
|
||||
if !exist {
|
||||
return errors.New("Proxy does not exist")
|
||||
}
|
||||
@ -45,21 +45,21 @@ func (s *Selector) Set(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewSelector(name string, proxys map[string]C.Proxy) (*Selector, error) {
|
||||
if len(proxys) == 0 {
|
||||
func NewSelector(name string, proxies map[string]C.Proxy) (*Selector, error) {
|
||||
if len(proxies) == 0 {
|
||||
return nil, errors.New("Provide at least one proxy")
|
||||
}
|
||||
|
||||
mapping := make(map[string]C.Proxy)
|
||||
var init string
|
||||
for k, v := range proxys {
|
||||
for k, v := range proxies {
|
||||
mapping[k] = v
|
||||
init = k
|
||||
}
|
||||
s := &Selector{
|
||||
name: name,
|
||||
proxys: mapping,
|
||||
selected: proxys[init],
|
||||
proxies: mapping,
|
||||
selected: proxies[init],
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ import (
|
||||
)
|
||||
|
||||
type URLTest struct {
|
||||
name string
|
||||
proxys []C.Proxy
|
||||
url *url.URL
|
||||
rawURL string
|
||||
addr *C.Addr
|
||||
fast C.Proxy
|
||||
delay time.Duration
|
||||
done chan struct{}
|
||||
name string
|
||||
proxies []C.Proxy
|
||||
url *url.URL
|
||||
rawURL string
|
||||
addr *C.Addr
|
||||
fast C.Proxy
|
||||
delay time.Duration
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func (u *URLTest) Name() string {
|
||||
@ -58,12 +58,12 @@ Loop:
|
||||
|
||||
func (u *URLTest) speedTest() {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(u.proxys))
|
||||
wg.Add(len(u.proxies))
|
||||
c := make(chan interface{})
|
||||
fast := selectFast(c)
|
||||
timer := time.NewTimer(u.delay)
|
||||
|
||||
for _, p := range u.proxys {
|
||||
for _, p := range u.proxies {
|
||||
go func(p C.Proxy) {
|
||||
err := getUrl(p, u.addr, u.rawURL)
|
||||
if err == nil {
|
||||
@ -129,7 +129,7 @@ func selectFast(in chan interface{}) chan interface{} {
|
||||
return out
|
||||
}
|
||||
|
||||
func NewURLTest(name string, proxys []C.Proxy, rawURL string, delay time.Duration) (*URLTest, error) {
|
||||
func NewURLTest(name string, proxies []C.Proxy, rawURL string, delay time.Duration) (*URLTest, error) {
|
||||
u, err := url.Parse(rawURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -154,14 +154,14 @@ func NewURLTest(name string, proxys []C.Proxy, rawURL string, delay time.Duratio
|
||||
}
|
||||
|
||||
urlTest := &URLTest{
|
||||
name: name,
|
||||
proxys: proxys[:],
|
||||
rawURL: rawURL,
|
||||
url: u,
|
||||
addr: addr,
|
||||
fast: proxys[0],
|
||||
delay: delay,
|
||||
done: make(chan struct{}),
|
||||
name: name,
|
||||
proxies: proxies[:],
|
||||
rawURL: rawURL,
|
||||
url: u,
|
||||
addr: addr,
|
||||
fast: proxies[0],
|
||||
delay: delay,
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
go urlTest.loop()
|
||||
return urlTest, nil
|
||||
|
Reference in New Issue
Block a user