mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-12 02:00:24 +00:00
✨ 搜图下载使用animeapi,将文件判存移至utils
This commit is contained in:
35
utils/file/dl.go
Normal file
35
utils/file/dl.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Package file 文件实用工具
|
||||
package file
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// DownloadTo 下载到路径
|
||||
func DownloadTo(url, file string) error {
|
||||
resp, err := http.Get(url)
|
||||
if err == nil {
|
||||
var f *os.File
|
||||
f, err = os.Create(file)
|
||||
if err == nil {
|
||||
_, err = io.Copy(f, resp.Body)
|
||||
resp.Body.Close()
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// IsExist 文件/路径存在
|
||||
func IsExist(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil || os.IsExist(err)
|
||||
}
|
||||
|
||||
// IsExist 文件/路径不存在
|
||||
func IsNotExist(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err != nil && os.IsNotExist(err)
|
||||
}
|
||||
Reference in New Issue
Block a user