Skip to content

Commit 626ee06

Browse files
committed
fix: 完善静态文件下载失败提示信息
1 parent 12a238f commit 626ee06

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

pkg/github/github.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Download(respositoryURL string, path string) {
3535
var client http.Client
3636
var wg sync.WaitGroup
3737
start := time.Now()
38-
fmt.Println("start to download static files, please waiting...")
38+
fmt.Println("Downloading static files, please wait...")
3939
handle(client, respositoryURL, path, &wg)
4040
wg.Wait()
4141

@@ -47,6 +47,14 @@ func Download(respositoryURL string, path string) {
4747
fmt.Printf("total time: %.2f s\n", float64(time.Since(start))/float64(time.Second))
4848
}
4949

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+
5058
// get all file link and download it
5159
func handle(client http.Client, url, path string, wg *sync.WaitGroup) {
5260
// if the path is not existed, then create it
@@ -56,7 +64,7 @@ func handle(client http.Client, url, path string, wg *sync.WaitGroup) {
5664
// get html source
5765
html, err := getHtml(client, url)
5866
if err != nil {
59-
panic(err)
67+
failedPrint(err)
6068
}
6169
// find all file and directory link
6270
links := urlPattern.FindAllSubmatch(html, -1)
@@ -81,14 +89,14 @@ func getFile(client http.Client, fileURL, path, filename string, wg *sync.WaitGr
8189

8290
resp, err := client.Get(fileURL)
8391
if err != nil {
84-
panic(err)
92+
failedPrint(err)
8593
}
8694
defer resp.Body.Close()
8795
var buff [1024]byte
8896
// 创建文件
8997
file, err := os.Create(filepath.Join(path, filename))
9098
if err != nil {
91-
panic(err)
99+
failedPrint(err)
92100
}
93101
defer file.Close()
94102
// 写入文件
@@ -101,7 +109,7 @@ func getFile(client http.Client, fileURL, path, filename string, wg *sync.WaitGr
101109
}
102110
// if failed delete this file
103111
os.Remove(filepath.Join(path, filename))
104-
panic(err)
112+
failedPrint(err)
105113
}
106114
file.Write(buff[:n])
107115
}

0 commit comments

Comments
 (0)