aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2015-10-08 17:04:37 +1000
committerGravatar alecdwm 2015-10-08 17:11:51 +1000
commitbc443ae2caca5038d4b837c0be36a4ab00fecec4 (patch)
treefbcc30df5c0b973df5606c42fe353d54b1f31236
parent7f753bedfc23a6bbfce06592283fb4166eb2bfae (diff)
Preliminary changes for user repo detection
-rw-r--r--lib/gogetme.go22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/gogetme.go b/lib/gogetme.go
index d520c87..89db20c 100644
--- a/lib/gogetme.go
+++ b/lib/gogetme.go
@@ -56,7 +56,7 @@ type GitHubUserData struct {
UpdatedAt string `json:"updated_at"`
}
-func getGitHubUserData(username string) *GitHubUserData {
+func getGitHubUserData(username string) GitHubUserData {
// Fetch
response, err := http.Get(fmt.Sprintf(
"https://api.github.com/users/%s",
@@ -64,7 +64,7 @@ func getGitHubUserData(username string) *GitHubUserData {
handleError("Fetching GitHub user data", err)
// Decode
- githubUserData := new(GitHubUserData)
+ var githubUserData GitHubUserData
err = json.NewDecoder(response.Body).Decode(&githubUserData)
handleError("Parsing response as JSON", err)
@@ -73,15 +73,13 @@ func getGitHubUserData(username string) *GitHubUserData {
}
func handler(w http.ResponseWriter, r *http.Request,
- customUrl, githubUser, githubUserAvatarURL string) {
+ customUrl, githubUser string, githubUserData GitHubUserData) {
t := time.Now()
fmt.Printf(
"[%s] Handled connection from: %s\n",
t.Format(time.RFC850),
r.RemoteAddr)
- // Todo: a minimal profile page with github user data,
- // maybe use layout from people at http://themes.getbootstrap.com/
// Todo: detect whether project exists on GitHub or not,
// and forward through to GitHub user page if not
// Todo: offer link to package documentation at godoc.org
@@ -192,11 +190,11 @@ func handler(w http.ResponseWriter, r *http.Request,
</body>
</html>
`,
- customUrl, // %[1]s
- r.URL.Path[1:], // %[2]s
- githubUser, // %[3]s
- githubUserAvatarURL, // %[4]s
- pageCss, // %[5]s
+ customUrl, // %[1]s
+ r.URL.Path[1:], // %[2]s
+ githubUser, // %[3]s
+ githubUserData.AvatarUrl, // %[4]s
+ pageCss, // %[5]s
)
fmt.Fprint(w, pageHtml)
@@ -204,13 +202,13 @@ func handler(w http.ResponseWriter, r *http.Request,
func Serve(customUrl, githubUser, listenPort string) {
// Process inputs
- githubUserAvatarURL := getGitHubUserData(githubUser).AvatarUrl
+ githubUserData := getGitHubUserData(githubUser)
listenPort = ":" + listenPort
// Prepare handler
// Todo: Add separate handler func for / vs /*, / is profile page for user
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- handler(w, r, customUrl, githubUser, githubUserAvatarURL)
+ handler(w, r, customUrl, githubUser, githubUserData)
})
// Listen and SERVE!