@@ -35,7 +35,7 @@ func Download(respositoryURL string, path string) {
35
35
var client http.Client
36
36
var wg sync.WaitGroup
37
37
start := time .Now ()
38
- fmt .Println ("start to download static files, please waiting ..." )
38
+ fmt .Println ("Downloading static files, please wait ..." )
39
39
handle (client , respositoryURL , path , & wg )
40
40
wg .Wait ()
41
41
@@ -47,6 +47,14 @@ func Download(respositoryURL string, path string) {
47
47
fmt .Printf ("total time: %.2f s\n " , float64 (time .Since (start ))/ float64 (time .Second ))
48
48
}
49
49
50
+ // failedPrint
51
+ func failedPrint (err error ) {
52
+ if err != nil {
53
+ fmt .Println ("Download static files failed! \r \n Please goto https://github.com/quarkcms/quark-go/tree/main/website url to download it \r \n After downloading, you must make 'install.lock' file in the website dir" )
54
+ panic (err )
55
+ }
56
+ }
57
+
50
58
// get all file link and download it
51
59
func handle (client http.Client , url , path string , wg * sync.WaitGroup ) {
52
60
// if the path is not existed, then create it
@@ -56,7 +64,7 @@ func handle(client http.Client, url, path string, wg *sync.WaitGroup) {
56
64
// get html source
57
65
html , err := getHtml (client , url )
58
66
if err != nil {
59
- panic (err )
67
+ failedPrint (err )
60
68
}
61
69
// find all file and directory link
62
70
links := urlPattern .FindAllSubmatch (html , - 1 )
@@ -81,14 +89,14 @@ func getFile(client http.Client, fileURL, path, filename string, wg *sync.WaitGr
81
89
82
90
resp , err := client .Get (fileURL )
83
91
if err != nil {
84
- panic (err )
92
+ failedPrint (err )
85
93
}
86
94
defer resp .Body .Close ()
87
95
var buff [1024 ]byte
88
96
// 创建文件
89
97
file , err := os .Create (filepath .Join (path , filename ))
90
98
if err != nil {
91
- panic (err )
99
+ failedPrint (err )
92
100
}
93
101
defer file .Close ()
94
102
// 写入文件
@@ -101,7 +109,7 @@ func getFile(client http.Client, fileURL, path, filename string, wg *sync.WaitGr
101
109
}
102
110
// if failed delete this file
103
111
os .Remove (filepath .Join (path , filename ))
104
- panic (err )
112
+ failedPrint (err )
105
113
}
106
114
file .Write (buff [:n ])
107
115
}
0 commit comments