Skip to content

Instantly share code, notes, and snippets.

@davidobrien1985
Last active May 26, 2019 11:14
Show Gist options
  • Save davidobrien1985/55520dcb8e4e93ea135427c70a323f85 to your computer and use it in GitHub Desktop.
Save davidobrien1985/55520dcb8e4e93ea135427c70a323f85 to your computer and use it in GitHub Desktop.
requires passing in of "user" parameter, example: `go run main.go -user=davidobrien1985`
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
)
var (
userPtr = flag.String("user", "", "This is the user name whose repos you like to scan. The URL looks like https://github.com/<user>.")
)
type Repos struct {
Name string `json:"name"`
FullName string `json:"full_name"`
}
func main() {
flag.Parse()
baseURL := "https://api.github.com"
getRepoNames(*userPtr, baseURL)
}
func getRepoNames(username string, url string) {
repoURL := url + "/users/" + username + "/repos"
fmt.Print(repoURL)
res, err := http.Get(repoURL)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
// fmt.Print(string(body))
var u []Repos
json.Unmarshal(body, &u)
fmt.Println(u)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment