2
0
mirror of synced 2025-02-24 06:38:14 +00:00

Simplify the tracker.New interface, just take a string

This commit is contained in:
Matt Joiner 2013-12-16 18:47:23 +11:00
parent 99d2ced31c
commit e68d5fec1f
2 changed files with 9 additions and 11 deletions

View File

@ -57,12 +57,17 @@ func RegisterClientScheme(scheme string, newFunc func(*url.URL) Client) {
schemes[scheme] = newFunc schemes[scheme] = newFunc
} }
func New(url *url.URL) (cl Client, err error) { // Returns ErrBadScheme if the tracker scheme isn't recognised.
newFunc, ok := schemes[url.Scheme] 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 { if !ok {
err = ErrBadScheme err = ErrBadScheme
return return
} }
cl = newFunc(url) cl = newFunc(url_s)
return return
} }

View File

@ -8,7 +8,6 @@ import (
"encoding/hex" "encoding/hex"
"io" "io"
"net" "net"
"net/url"
"syscall" "syscall"
"testing" "testing"
) )
@ -84,13 +83,7 @@ func TestConvertInt16ToInt(t *testing.T) {
} }
func TestUDPTracker(t *testing.T) { func TestUDPTracker(t *testing.T) {
tr, err := tracker.New(func() *url.URL { tr, err := tracker.New("udp://tracker.openbittorrent.com:80/announce")
u, err := url.Parse("udp://tracker.openbittorrent.com:80/announce")
if err != nil {
t.Fatal(err)
}
return u
}())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }