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

24 lines
380 B
Go

package utils
import (
"net/http"
"time"
)
func GetWithRetry(url string) (resp *http.Response, err error) {
retryTimes := 3
haveTried := 0
retryDelay := time.Second // 延迟1秒再重试
for haveTried < retryTimes {
get, err := http.Get(url)
if err != nil {
haveTried++
time.Sleep(retryDelay)
continue
} else {
return get, nil
}
}
return nil, err
}