aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar alecdwm 2015-10-01 13:45:34 +1000
committerGravatar alecdwm 2015-10-01 13:46:36 +1000
commite19b85cbd312a393bd27e0ccc7e1550201a5dac5 (patch)
treedb08196cf7f90a0b776078984996fb3a36a209d3
parentff040436d737cf91cee73010f4e8fd946700b704 (diff)
Split package and CLI
+ Split into package (gogetme) and CLI (main)
-rw-r--r--cli/gogetme.go23
-rw-r--r--errors.go26
-rw-r--r--main.go (renamed from gogetme.go)17
3 files changed, 55 insertions, 11 deletions
diff --git a/cli/gogetme.go b/cli/gogetme.go
new file mode 100644
index 0000000..287b2f3
--- /dev/null
+++ b/cli/gogetme.go
@@ -0,0 +1,23 @@
+// 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/errors.go
new file mode 100644
index 0000000..f2768fc
--- /dev/null
+++ b/errors.go
@@ -0,0 +1,26 @@
+// 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 gogetme
+
+import "fmt"
+
+func handleError(str string, err error) {
+ if err != nil {
+ fmt.Println(err)
+ panic("Error: " + str)
+ }
+}
diff --git a/gogetme.go b/main.go
index 9922727..9c28f83 100644
--- a/gogetme.go
+++ b/main.go
@@ -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 main
+package gogetme
import (
"bufio"
@@ -118,11 +118,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
gitHubUser, r.URL.Path[1:], "Click here to go to the repository")
}
-func main() {
+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")
- listenPort := ":9999"
flag.StringVar(&listenPort, "listenPort", "unset", "port to listen for connections on")
flag.Parse()
@@ -165,12 +165,7 @@ func main() {
// Listen and SERVE!
fmt.Print("\nHandling connections:\n")
http.HandleFunc("/", handler)
- http.ListenAndServe(listenPort, nil)
-}
-
-func handleError(str string, err error) {
- if err != nil {
- fmt.Println(err)
- panic("Error: " + str)
- }
+ // Todo: ListenAndServeTLS
+ err := http.ListenAndServe(listenPort, nil)
+ handleError("Serving HTTP requests", err)
}