From 23d5bf0b51aac91201f1a1ab933d7c856e80357c Mon Sep 17 00:00:00 2001 From: Eric Ripa Date: Thu, 9 Aug 2018 10:05:47 -0700 Subject: [PATCH] Add simply TCP check during optsGuard to verify the given github URL --- main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 23df5875..eb675856 100644 --- a/main.go +++ b/main.go @@ -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 != "" {