mirror of
https://github.com/nitezs/sub2sing-box.git
synced 2024-12-23 15:14:43 -05:00
28 lines
421 B
Go
Executable File
28 lines
421 B
Go
Executable File
package util
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
func Fetch(url string, maxRetryTimes int) (string, error) {
|
|
retryTime := 0
|
|
var err error
|
|
var resp *http.Response
|
|
for retryTime < maxRetryTimes {
|
|
resp, err = http.Get(url)
|
|
if err != nil {
|
|
retryTime++
|
|
continue
|
|
}
|
|
var data []byte
|
|
data, err = io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
retryTime++
|
|
continue
|
|
}
|
|
return string(data), err
|
|
}
|
|
return "", err
|
|
}
|