1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-24 11:04:42 -05:00
sub2clash/utils/get.go
2023-09-13 00:46:17 +08:00

31 lines
615 B
Go

package utils
import (
"errors"
"net/http"
"sub2clash/config"
"time"
)
func Get(url string) (resp *http.Response, err error) {
retryTimes := config.Default.RequestRetryTimes
haveTried := 0
retryDelay := time.Second // 延迟1秒再重试
for haveTried < retryTimes {
get, err := http.Get(url)
if err != nil {
haveTried++
time.Sleep(retryDelay)
continue
} else {
// 如果文件大小大于设定,直接返回错误
if get != nil && get.ContentLength > config.Default.RequestMaxFileSize {
return nil, errors.New("文件过大")
}
return get, nil
}
}
return nil, err
}