Break Change: use yml, which is easier to parse, as the config format

This commit is contained in:
Dreamacro
2018-10-02 15:26:36 +08:00
parent 16c9445459
commit 5c7fa6b18b
12 changed files with 222 additions and 186 deletions

View File

@ -1,6 +1,7 @@
package adapters
import (
"errors"
"sync"
"time"
@ -16,6 +17,13 @@ type URLTest struct {
done chan struct{}
}
type URLTestOption struct {
Name string `proxy:"name"`
Proxies []string `proxy:"proxies"`
URL string `proxy:"url"`
Delay int `proxy:"delay"`
}
func (u *URLTest) Name() string {
return u.name
}
@ -83,16 +91,20 @@ func (u *URLTest) speedTest() {
}
}
func NewURLTest(name string, proxies []C.Proxy, rawURL string, delay time.Duration) (*URLTest, error) {
_, err := urlToMetadata(rawURL)
func NewURLTest(option URLTestOption, proxies []C.Proxy) (*URLTest, error) {
_, err := urlToMetadata(option.URL)
if err != nil {
return nil, err
}
if len(proxies) < 1 {
return nil, errors.New("The number of proxies cannot be 0")
}
delay := time.Duration(option.Delay) * time.Second
urlTest := &URLTest{
name: name,
name: option.Name,
proxies: proxies[:],
rawURL: rawURL,
rawURL: option.URL,
fast: proxies[0],
delay: delay,
done: make(chan struct{}),