1
0
mirror of https://github.com/zu1k/nali.git synced 2025-02-09 05:42:43 +08:00
nali/pkg/cdn/update.go
zu1k d1b584c3e7 refactor: better download and error handle
Signed-off-by: zu1k <i@lgf.im>
2022-03-02 12:34:11 +08:00

29 lines
717 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cdn
import (
"log"
"github.com/zu1k/nali/pkg/common"
)
const (
githubUrl = "https://raw.githubusercontent.com/SukkaLab/cdn/master/dist/cdn.json"
jsdelivrUrl = "https://cdn.jsdelivr.net/gh/SukkaLab/cdn/dist/cdn.json"
)
func Download(filePath ...string) (data []byte, err error) {
data, err = common.GetHttpClient().Get(jsdelivrUrl, githubUrl)
if err != nil {
log.Printf("CDN数据库下载失败请手动下载解压后保存到本地: %s \n", filePath)
log.Println("下载链接:", githubUrl)
return
}
if len(filePath) == 1 {
if err := common.SaveFile(filePath[0], data); err == nil {
log.Printf("已将最新的 CDN数据库 保存到本地: %s \n", filePath)
}
}
return
}