frontend: specify timeout for requests (#29)

This commit is contained in:
Yuhui Xu
2021-08-02 18:46:43 +08:00
committed by GitHub
parent bee26f421c
commit 234aadadd9
2 changed files with 5 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import (
"net/url"
"strconv"
"strings"
"time"
)
type channelData struct {
@@ -46,7 +47,8 @@ func batchRequest(servers []string, endpoint string, command string) []string {
}
url := "http://" + hostname + ":" + strconv.Itoa(setting.proxyPort) + "/" + url.PathEscape(endpoint) + "?q=" + url.QueryEscape(command)
go func(url string, i int) {
response, err := http.Get(url)
client := http.Client{Timeout: 5 * time.Second}
response, err := client.Get(url)
if err != nil {
ch <- channelData{i, "request failed: " + err.Error() + "\n"}
return