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"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
@@ -15,6 +16,7 @@ import (
"regexp"
"strings"
"sync"
"time"
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -748,10 +750,19 @@ func optsGuard() error {
if !strings.HasSuffix(opts.GithubURL, "/") {
opts.GithubURL += "/"
}
_, err := url.Parse(opts.GithubURL)
ghURL, err := url.Parse(opts.GithubURL)
if err != nil {
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 != "" {