增加ip2region下载db错误处理

This commit is contained in:
tsosunchia
2023-10-05 00:55:44 +08:00
parent d444ff3c62
commit 7b145f4e64

View File

@@ -23,14 +23,24 @@ func downloadDataBase() error {
if err != nil {
return err
}
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
panic(err)
}
}(resp.Body)
// Create the file
out, err := os.Create(ipDataBasePath)
if err != nil {
return err
}
defer out.Close()
defer func(out *os.File) {
err := out.Close()
if err != nil {
panic(err)
}
}(out)
// Write the body to file
_, err = io.Copy(out, resp.Body)