From bbfc6effdca3f7d620ca706a80197e681b28f9c2 Mon Sep 17 00:00:00 2001 From: Jonathan DeMasi Date: Wed, 5 Jun 2019 11:09:07 -0600 Subject: init --- .gitignore | 12 +++++++++++ main.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .gitignore create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1c181e --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out diff --git a/main.go b/main.go new file mode 100644 index 0000000..3ebcb97 --- /dev/null +++ b/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "fmt" + "log" + "net" + "os" + "net/http" + "io/ioutil" +) + +func parseArgs() string { + // Check for at least one arg, bail if none + if len(os.Args) < 2 { + log.Fatalln("You must provide exactly one GitHub username.") + } + + // We have one arg possible comma separated + if len(os.Args) == 2 { + return(os.Args[1]) + } else { + log.Fatalln("You have provided too many arguments") + } + return("") +} + +func fetchKeys(username string) string { + log.Printf("Fetching keys for user %s", username) + + url := fmt.Sprintf("https://github.com/%s.keys", username) + resp, err := http.Get(url) + if err != nil { + log.Fatal(err) + } + + defer resp.Body.Close() + + if resp.StatusCode == http.StatusOK { + bodyBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + bodyString := string(bodyBytes) + return(bodyString) + } + return("") +} + +// Need to fix this to not be an infinite loop +func checkResolvers() { + for { + _, err := net.LookupIP("github.com") + if err != nil { + log.Println("No DNS yet...") + } else { + break + } + } + return +} + +func main() { + username := parseArgs() + checkResolvers() + //fmt.Println(username) + keys := fetchKeys(username) + fmt.Print(keys) + return +} -- cgit v1.2.3