Add simply TCP check during optsGuard to verify the given github URL

This commit is contained in:
Eric Ripa authored and Eric Ripa committed 2018-08-09 11:30:55 -07:00
1 parent b1c7a84fae
commit 23d5bf0b51
1 file changed
+12 -1
+12 -1
View File
@@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@@ -15,6 +16,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"sync" "sync"
"time"
"gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing"
@@ -748,10 +750,19 @@ func optsGuard() error {
if !strings.HasSuffix(opts.GithubURL, "/") { if !strings.HasSuffix(opts.GithubURL, "/") {
opts.GithubURL += "/" opts.GithubURL += "/"
} }
_, err := url.Parse(opts.GithubURL) ghURL, err := url.Parse(opts.GithubURL)
if err != nil { if err != nil {
return err return err
} }
tcpPort := "443"
if ghURL.Scheme == "http" {
tcpPort = "80"
}
timeout := time.Duration(1 * time.Second)
_, err = net.DialTimeout("tcp", ghURL.Host+":"+tcpPort, timeout)
if err != nil {
return fmt.Errorf("%s unreachable, error: %s", ghURL.Host, err)
}
} }
if opts.SingleSearch != "" { if opts.SingleSearch != "" {