1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 22:04:41 -05:00
sub2clash/utils/get.go

24 lines
380 B
Go
Raw Normal View History

2023-09-12 06:40:24 -04:00
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
}