mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 18:10:29 +00:00
feat: support custom tracker url (#59)
This commit is contained in:
1 parent
9ef3405e43
commit
691c2f496e
71 files changed
+2209
-891
No files matched your search
@@ -0,0 +1,14 @@
|
||||
package util
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
func MapToStruct(s any, v any) error {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
b, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal(b, v)
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package util
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseSchema(t *testing.T) {
|
||||
type args struct {
|
||||
url string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "http",
|
||||
args: args{
|
||||
url: "http://www.google.com",
|
||||
},
|
||||
want: "HTTP",
|
||||
},
|
||||
{
|
||||
name: "https",
|
||||
args: args{
|
||||
url: "https://www.google.com",
|
||||
},
|
||||
want: "HTTPS",
|
||||
},
|
||||
{
|
||||
name: "file",
|
||||
args: args{
|
||||
url: "file:///home/bt.torrent",
|
||||
},
|
||||
want: "FILE",
|
||||
},
|
||||
{
|
||||
name: "file-no-scheme",
|
||||
args: args{
|
||||
url: "/home/bt.torrent",
|
||||
},
|
||||
want: "FILE",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := ParseSchema(tt.args.url); got != tt.want {
|
||||
t.Errorf("ParseSchema() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user