29 lines
675 B
Go
29 lines
675 B
Go
package downloader
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDownloader(t *testing.T) {
|
|
url := "https://mirrors.tuna.tsinghua.edu.cn/Adoptium/8/jdk/x64/windows/OpenJDK8U-jdk_x64_windows_hotspot_8u382b05.zip"
|
|
dir := os.TempDir()
|
|
fmt.Println(dir)
|
|
fileName := "OpenJDK8U-jdk_x64_windows_hotspot_8u382b05.zip"
|
|
|
|
a, _ := getRedirectInfo(url, UserAgent)
|
|
location := a.Header.Get("Location")
|
|
if len(location) == 0 {
|
|
location = url
|
|
}
|
|
startTime := time.Now()
|
|
d := NewDownloader(location, dir, fileName, 5)
|
|
if err := d.Run(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Printf("\n 文件下载完成耗时: %f second\n", time.Now().Sub(startTime).Seconds())
|
|
}
|