aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2015-10-02 13:43:44 +1000
committerGravatar alecdwm 2015-10-02 13:43:44 +1000
commit992db5e030de5a85d34b143548d887ffc179e9c5 (patch)
tree9e208aa6aeec35fddb28a9e2956c0a717e49dd82
parente19b85cbd312a393bd27e0ccc7e1550201a5dac5 (diff)
Multiple changes
+ Added installation section to README + Updated 'about program' section of licensing + Modified program directory structure for better go get compatibility + Improved readability in areas
-rw-r--r--README.md9
-rw-r--r--cli/gogetme.go23
-rw-r--r--lib/errors.go (renamed from errors.go)4
-rw-r--r--lib/gogetme.go191
-rw-r--r--main.go158
5 files changed, 206 insertions, 179 deletions
diff --git a/README.md b/README.md
index b3b83fd..8e36d8c 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,9 @@
# GoGetMe
-A small program to assist in hosting go packages on your own domain name
+go get your GitHub-hosted Go packages via your own domain
+
+# Installation
+Installation requires [Go](https://golang.org/)
+```bash
+$ go get go.owls.io/gogetme
+$ gogetme
+```
diff --git a/cli/gogetme.go b/cli/gogetme.go
deleted file mode 100644
index 287b2f3..0000000
--- a/cli/gogetme.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// GoGetMe - A small program to assist in hosting go packages on your own domain name
-// Copyright (C) 2015 alecdwm
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package main
-
-import "go.owls.io/gogetme"
-
-func main() {
- gogetme.Go()
-}
diff --git a/errors.go b/lib/errors.go
index f2768fc..118eba6 100644
--- a/errors.go
+++ b/lib/errors.go
@@ -1,4 +1,4 @@
-// GoGetMe - A small program to assist in hosting go packages on your own domain name
+// GoGetMe - go get your GitHub-hosted Go packages via your own domain
// Copyright (C) 2015 alecdwm
// This program is free software: you can redistribute it and/or modify
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-package gogetme
+package lib
import "fmt"
diff --git a/lib/gogetme.go b/lib/gogetme.go
new file mode 100644
index 0000000..e354362
--- /dev/null
+++ b/lib/gogetme.go
@@ -0,0 +1,191 @@
+// GoGetMe - go get your GitHub-hosted Go packages via your own domain
+// Copyright (C) 2015 alecdwm
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package lib
+
+import (
+ "bufio"
+ "encoding/json"
+ "flag"
+ "fmt"
+ "net/http"
+ "os"
+ "strings"
+ "time"
+)
+
+var customUrl string
+var gitHubUser string
+var gitHubUserAvatarURL string
+
+type GitHubUserData struct {
+ Login string `json:"login"`
+ Id int `json:"id"`
+ AvatarUrl string `json:"avatar_url"`
+ GravatarId string `json:"gravatar_id"`
+ Url string `json:"url"`
+ HtmlUrl string `json:"html_url"`
+ FollowersUrl string `json:"followers_url"`
+ FollowingUrl string `json:"following_url"`
+ GistsUrl string `json:"gists_url"`
+ StarredUrl string `json:"starred_url"`
+ SubscriptionsUrl string `json:"subscriptions_url"`
+ OrganizationsUrl string `json:"organizations_url"`
+ ReposUrl string `json:"repos_url"`
+ EventsUrl string `json:"events_url"`
+ ReceivedEventsUrl string `json:"received_events_url"`
+ Type string `json:"type"`
+ SiteAdmin bool `json:"site_admin"`
+ Name string `json:"name"`
+ Company string `json:"company"`
+ Blog string `json:"blog"`
+ Location string `json:"location"`
+ Email string `json:"email"`
+ Hireable bool `json:"hireable"`
+ Bio bool `json:"bio"`
+ PublicRepos int `json:"public_repos"`
+ PublicGists int `json:"public_gists"`
+ Followers int `json:"followers"`
+ Following int `json:"following"`
+ CreatedAt string `json:"created_at"`
+ UpdatedAt string `json:"updated_at"`
+}
+
+func getGitHubUserData(username string) *GitHubUserData {
+ // Fetch
+ response, err := http.Get(fmt.Sprintf(
+ "https://api.github.com/users/%s",
+ username))
+ handleError("Fetching GitHub user data", err)
+
+ // Decode
+ gitHubUserData := new(GitHubUserData)
+ err = json.NewDecoder(response.Body).Decode(&gitHubUserData)
+ handleError("Parsing response as JSON", err)
+
+ // Return
+ return gitHubUserData
+}
+
+func handler(w http.ResponseWriter, r *http.Request) {
+ 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
+ fmt.Fprintf(w,
+ "<!DOCTYPE html>\n"+
+ "<html lang=\"en\">\n"+
+ "<head>\n"+
+ "<meta charset=\"utf-8\">\n"+
+ "<meta name=\"go-import\" content=\"%s git https://github.com/%s/%s.git\">\n"+
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"+
+ "<title>%s %s/%s</title>\n"+
+ "<link href=\"https://maxcdn.bootstrapcdn.com/bootswatch/3.3.5/darkly/bootstrap.min.css\" rel=\"stylesheet\" crossorigin=\"anonymous\">\n"+
+ "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>\n"+
+ "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js\" crossorigin=\"anonymous\"></script>\n"+
+ "</head>\n"+
+ "<body>\n"+
+ "<div class=\"container\">\n"+
+ "<div class=\"panel panel-default\">\n"+
+ "<img class=\"pull-left panel-profile-img img-circle\" style=\"width:120px;height:120px;\" src=\"%s\" />\n"+
+ "<div class=\"panel-body text-center\">\n"+
+ "<h1 class=\"text-right panel-title\">%s</h5>\n"+
+ "<p class=\"text-right\">%s/%s</p>\n"+
+ "<a href=\"https://github.com/%s/%s\" class=\"pull-right btn btn-primary-outline btn-sm\">%s</a>\n"+
+ "</div>\n"+
+ "</div>\n"+
+ "</div>\n"+
+ "</div>\n"+
+ "</body>\n"+
+ "</html>",
+ customUrl+"/"+r.URL.Path[1:], gitHubUser, r.URL.Path[1:],
+ customUrl, gitHubUser, r.URL.Path[1:],
+ gitHubUserAvatarURL,
+ gitHubUser,
+ customUrl, r.URL.Path[1:],
+ gitHubUser, r.URL.Path[1:], "Click here to go to the repository")
+}
+
+func GoGetMe() {
+ // Get ready to GO!
+ listenPort := ":9999"
+ flag.StringVar(
+ &customUrl,
+ "customUrl",
+ "unset", "URL to host your Go packages at")
+
+ flag.StringVar(
+ &gitHubUser,
+ "gitHubUser",
+ "unset",
+ "your GitHub username")
+
+ flag.StringVar(&listenPort,
+ "listenPort",
+ "unset",
+ "port to listen for connections on")
+
+ flag.Parse()
+
+ reader := bufio.NewReader(os.Stdin)
+ if customUrl == "unset" {
+ fmt.Print("Input Custom Go Import URL > ")
+
+ input, err := reader.ReadString('\n')
+ handleError("Reading input string", err)
+
+ customUrl = strings.Trim(input, "\n")
+ }
+ fmt.Printf("\nCustom Go Import URL set to '%s'\n", customUrl)
+
+ if gitHubUser == "unset" {
+ fmt.Print("\nInput GitHub Username > ")
+
+ input, err := reader.ReadString('\n')
+ handleError("Reading input string", err)
+
+ gitHubUser = strings.Trim(input, "\n")
+ }
+ fmt.Printf("\nGitHub Username set to '%s'\n", gitHubUser)
+
+ gitHubUserAvatarURL = getGitHubUserData(gitHubUser).AvatarUrl
+ fmt.Printf("\nGitHub Avatar URL set to '%s'\n", gitHubUserAvatarURL)
+
+ if listenPort == "unset" {
+ fmt.Print("\nInput port to listen on > ")
+
+ input, err := reader.ReadString('\n')
+ handleError("Reading input string", err)
+
+ listenPort = ":" + strings.Trim(input, "\n")
+ } else {
+ listenPort = ":" + listenPort
+ }
+ fmt.Printf("\nListen port set to '%s'\n", listenPort)
+
+ // Listen and SERVE!
+ fmt.Print("\nHandling connections:\n")
+ http.HandleFunc("/", handler)
+ // Todo: ListenAndServeTLS
+ err := http.ListenAndServe(listenPort, nil)
+ handleError("Serving HTTP requests", err)
+}
diff --git a/main.go b/main.go
index 9c28f83..07282c5 100644
--- a/main.go
+++ b/main.go
@@ -1,4 +1,4 @@
-// GoGetMe - A small program to assist in hosting go packages on your own domain name
+// GoGetMe - go get your GitHub-hosted Go packages via your own domain
// Copyright (C) 2015 alecdwm
// This program is free software: you can redistribute it and/or modify
@@ -14,158 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-package gogetme
+package main
-import (
- "bufio"
- "encoding/json"
- "flag"
- "fmt"
- "net/http"
- "os"
- "strings"
- "time"
-)
+import gogetme "go.owls.io/gogetme/lib"
-var customUrl string
-var gitHubUser string
-var gitHubUserAvatarURL string
-
-type GitHubUserData struct {
- Login string `json:"login"`
- Id int `json:"id"`
- AvatarUrl string `json:"avatar_url"`
- GravatarId string `json:"gravatar_id"`
- Url string `json:"url"`
- HtmlUrl string `json:"html_url"`
- FollowersUrl string `json:"followers_url"`
- FollowingUrl string `json:"following_url"`
- GistsUrl string `json:"gists_url"`
- StarredUrl string `json:"starred_url"`
- SubscriptionsUrl string `json:"subscriptions_url"`
- OrganizationsUrl string `json:"organizations_url"`
- ReposUrl string `json:"repos_url"`
- EventsUrl string `json:"events_url"`
- ReceivedEventsUrl string `json:"received_events_url"`
- Type string `json:"type"`
- SiteAdmin bool `json:"site_admin"`
- Name string `json:"name"`
- Company string `json:"company"`
- Blog string `json:"blog"`
- Location string `json:"location"`
- Email string `json:"email"`
- Hireable bool `json:"hireable"`
- Bio bool `json:"bio"`
- PublicRepos int `json:"public_repos"`
- PublicGists int `json:"public_gists"`
- Followers int `json:"followers"`
- Following int `json:"following"`
- CreatedAt string `json:"created_at"`
- UpdatedAt string `json:"updated_at"`
-}
-
-func getGitHubUserData(username string) *GitHubUserData {
- // Fetch
- response, err := http.Get(fmt.Sprintf("https://api.github.com/users/%s", username))
- handleError("Fetching GitHub user data", err)
-
- // Decode
- gitHubUserData := new(GitHubUserData)
- err = json.NewDecoder(response.Body).Decode(&gitHubUserData)
- handleError("Parsing response as JSON", err)
-
- // Return
- return gitHubUserData
-}
-
-func handler(w http.ResponseWriter, r *http.Request) {
- 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
- fmt.Fprintf(w,
- "<!DOCTYPE html>\n"+
- "<html lang=\"en\">\n"+
- "<head>\n"+
- "<meta charset=\"utf-8\">\n"+
- "<meta name=\"go-import\" content=\"%s git https://github.com/%s/%s.git\">\n"+
- "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"+
- "<title>%s %s/%s</title>\n"+
- "<link href=\"https://maxcdn.bootstrapcdn.com/bootswatch/3.3.5/darkly/bootstrap.min.css\" rel=\"stylesheet\" crossorigin=\"anonymous\">\n"+
- "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>\n"+
- "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js\" crossorigin=\"anonymous\"></script>\n"+
- "</head>\n"+
- "<body>\n"+
- "<div class=\"container\">\n"+
- "<div class=\"panel panel-default\">\n"+
- "<img class=\"pull-left panel-profile-img img-circle\" style=\"width:120px;height:120px;\" src=\"%s\" />\n"+
- "<div class=\"panel-body text-center\">\n"+
- "<h1 class=\"text-right panel-title\">%s</h5>\n"+
- "<p class=\"text-right\">%s/%s</p>\n"+
- "<a href=\"https://github.com/%s/%s\" class=\"pull-right btn btn-primary-outline btn-sm\">%s</a>\n"+
- "</div>\n"+
- "</div>\n"+
- "</div>\n"+
- "</div>\n"+
- "</body>\n"+
- "</html>",
- customUrl+"/"+r.URL.Path[1:], gitHubUser, r.URL.Path[1:],
- customUrl, gitHubUser, r.URL.Path[1:],
- gitHubUserAvatarURL,
- gitHubUser,
- customUrl, r.URL.Path[1:],
- gitHubUser, r.URL.Path[1:], "Click here to go to the repository")
-}
-
-func Go() {
- // Get ready to GO!
- listenPort := ":9999"
- flag.StringVar(&customUrl, "customUrl", "unset", "URL to host your Go packages at")
- flag.StringVar(&gitHubUser, "gitHubUser", "unset", "your GitHub username")
- flag.StringVar(&listenPort, "listenPort", "unset", "port to listen for connections on")
- flag.Parse()
-
- reader := bufio.NewReader(os.Stdin)
- if customUrl == "unset" {
- fmt.Print("Input Custom Go Import URL > ")
-
- input, err := reader.ReadString('\n')
- handleError("Reading input string", err)
-
- customUrl = strings.Trim(input, "\n")
- }
- fmt.Printf("\nCustom Go Import URL set to '%s'\n", customUrl)
-
- if gitHubUser == "unset" {
- fmt.Print("\nInput GitHub Username > ")
-
- input, err := reader.ReadString('\n')
- handleError("Reading input string", err)
-
- gitHubUser = strings.Trim(input, "\n")
- }
- fmt.Printf("\nGitHub Username set to '%s'\n", gitHubUser)
-
- gitHubUserAvatarURL = getGitHubUserData(gitHubUser).AvatarUrl
- fmt.Printf("\nGitHub Avatar URL set to '%s'\n", gitHubUserAvatarURL)
-
- if listenPort == "unset" {
- fmt.Print("\nInput port to listen on > ")
-
- input, err := reader.ReadString('\n')
- handleError("Reading input string", err)
-
- listenPort = ":" + strings.Trim(input, "\n")
- } else {
- listenPort = ":" + listenPort
- }
- fmt.Printf("\nListen port set to '%s'\n", listenPort)
-
- // Listen and SERVE!
- fmt.Print("\nHandling connections:\n")
- http.HandleFunc("/", handler)
- // Todo: ListenAndServeTLS
- err := http.ListenAndServe(listenPort, nil)
- handleError("Serving HTTP requests", err)
+func main() {
+ gogetme.GoGetMe()
}