1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-24 12:04:42 -05:00
sub2sing-box/util/fetch.go
2024-03-20 20:54:23 +08:00

26 lines
380 B
Go

package util
import (
"io"
"net/http"
)
func Fetch(url string, maxRetryTimes int) (string, error) {
retryTime := 0
var err error
for retryTime < maxRetryTimes {
resp, err := http.Get(url)
if err != nil {
retryTime++
continue
}
data, err := io.ReadAll(resp.Body)
if err != nil {
retryTime++
continue
}
return string(data), err
}
return "", err
}