]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Simplify the tracker.New interface, just take a string
authorMatt Joiner <anacrolix@gmail.com>
Mon, 16 Dec 2013 07:47:23 +0000 (18:47 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 16 Dec 2013 07:47:23 +0000 (18:47 +1100)
tracker/tracker.go
tracker/udp/udp_tracker_test.go

index 701bacc04051adadc59ff5f681137815ef75040a..820880b408657480ee1308957b0adda8bbba73db 100644 (file)
@@ -57,12 +57,17 @@ func RegisterClientScheme(scheme string, newFunc func(*url.URL) Client) {
        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
 }
index c9ba04c2ed464f6f1587af6d536b6896d0f332ca..4f524fd5fd279eb02aa5bbb60ea39a2ddc8f2a64 100644 (file)
@@ -8,7 +8,6 @@ import (
        "encoding/hex"
        "io"
        "net"
-       "net/url"
        "syscall"
        "testing"
 )
@@ -84,13 +83,7 @@ func TestConvertInt16ToInt(t *testing.T) {
 }
 
 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)
        }