schemes[scheme] = newFunc
}
-func New(url *url.URL) (cl Client, err error) {
- newFunc, ok := schemes[url.Scheme]
+// Returns ErrBadScheme if the tracker scheme isn't recognised.
+func New(rawurl string) (cl Client, err error) {
+ url_s, err := url.Parse(rawurl)
+ if err != nil {
+ return
+ }
+ newFunc, ok := schemes[url_s.Scheme]
if !ok {
err = ErrBadScheme
return
}
- cl = newFunc(url)
+ cl = newFunc(url_s)
return
}
"encoding/hex"
"io"
"net"
- "net/url"
"syscall"
"testing"
)
}
func TestUDPTracker(t *testing.T) {
- tr, err := tracker.New(func() *url.URL {
- u, err := url.Parse("udp://tracker.openbittorrent.com:80/announce")
- if err != nil {
- t.Fatal(err)
- }
- return u
- }())
+ tr, err := tracker.New("udp://tracker.openbittorrent.com:80/announce")
if err != nil {
t.Fatal(err)
}