Kaynağa Gözat

Fix endless wait when remote list is not available

Signed-off-by: Antoine Tenart <antoine.tenart@ack.tf>
Antoine Tenart 3 yıl önce
ebeveyn
işleme
5db45b266f
1 değiştirilmiş dosya ile 6 ekleme ve 1 silme
  1. 6 1
      main.go

+ 6 - 1
main.go

@@ -11,6 +11,7 @@ import (
 	"net/http"
 	"os"
 	"strings"
+	"time"
 )
 
 var (
@@ -83,6 +84,7 @@ func (s *Server) generateList(w http.ResponseWriter, r *http.Request) {
 func handle(url string, zone chan string) {
 	body, err := fetch(url)
 	if err != nil {
+		zone <- ""
 		return
 	}
 
@@ -90,7 +92,10 @@ func handle(url string, zone chan string) {
 }
 
 func fetch(url string) (string, error) {
-	req, err := http.Get(url)
+	client := http.Client{
+		Timeout: 3 * time.Second,
+	}
+	req, err := client.Get(url)
 	if err != nil {
 		return "", err
 	}