ZeroBot-Plugin/utils/file/dl.go
fumiama cb44758036 ✏️ 修复 manager 定时器错误
同时 make lint happy
2021-12-26 14:07:05 +08:00

39 lines
636 B
Go

// Package file 文件实用工具
package file
import (
"crypto/tls"
"io"
"net/http"
"os"
)
var (
tr = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
nochkcrtcli = &http.Client{Transport: tr}
)
// DownloadTo 下载到路径
//nolint: bodyclose
func DownloadTo(url, file string, chkcrt bool) error {
var resp *http.Response
var err error
if chkcrt {
resp, err = http.Get(url)
} else {
resp, err = nochkcrtcli.Get(url)
}
if err == nil {
var f *os.File
f, err = os.Create(file)
if err == nil {
_, err = io.Copy(f, resp.Body)
f.Close()
}
resp.Body.Close()
}
return err
}