123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package downloader
- import (
- "fmt"
- "git.bvbej.com/bvbej/base-golang/pkg/downloader/base"
- "git.bvbej.com/bvbej/base-golang/pkg/downloader/controller"
- "git.bvbej.com/bvbej/base-golang/tool"
- "golang.org/x/net/proxy"
- "net/http"
- "net/url"
- "runtime"
- "testing"
- "time"
- )
- func TestNewDownloader(t *testing.T) {
- dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:1080", nil, proxy.Direct)
- parse, _ := url.Parse(`socks5://127.0.0.1:1080`)
- if err != nil {
- t.Fatal(err, dialer)
- }
- err = <-New(
- controller.WithDialer(dialer), // todo: use dialer proxy
- controller.WithCookie(nil),
- controller.WithProxy(http.ProxyURL(parse)), // todo: use http client proxy
- controller.WithTimeout(time.Second*3),
- ).URL("http://10.0.1.34/com.tencent.tmgp.jxqy.apk").
- Listener(func(event *Event) {
- if event.Key == EventKeyFinally {
- fmt.Println("下载完成!")
- }
- if event.Key == EventKeyProgress {
- fmt.Printf("下载速度:%s/s 已下载:%s 已用时:%s \n",
- tool.ByteFmt(event.Task.Progress.Speed),
- tool.ByteFmt(event.Task.Progress.Downloaded),
- time.Duration(event.Task.Progress.Used),
- )
- }
- }).
- Create(&base.Options{
- Connections: runtime.NumCPU(),
- })
- t.Log(err)
- }
|