about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-11-06 15:08:22 +0100
committerEmile <hanemile@protonmail.com>2019-11-06 15:08:22 +0100
commitd753975ae9c6c82c3569a48597ef752b85b4abc8 (patch)
tree80457a6e7f8d4b12a76c00f3879477678c54e097
parentcfc38aaac1412a7631aeb021adf3f6c765005cb4 (diff)
basic setup
-rw-r--r--src/http.go35
-rw-r--r--src/main.go16
2 files changed, 51 insertions, 0 deletions
diff --git a/src/http.go b/src/http.go
new file mode 100644
index 0000000..7c0db12
--- /dev/null
+++ b/src/http.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+	"net/http"
+
+	"github.com/gorilla/mux"
+)
+
+var (
+	port *int
+)
+
+// setupHTTPServer returns an http server
+func setupHTTPServer() http.Server {
+	r := mux.NewRouter()
+
+	r.HandleFunc("/", indexHandler).Methods("GET")
+
+	return http.Server{
+		Addr:    fmt.Sprintf("0.0.0.0:%d", *port),
+		Handler: r,
+	}
+}
+
+// registerHTTPFlags registers the flags needed for the http server
+func registerHTTPFlags() {
+	port = flag.Int("p", 8084, "The port for the HTTP server")
+}
+
+// indexHandler handles requests to the "/" endpoint
+func indexHandler(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "%s", "asd")
+}
diff --git a/src/main.go b/src/main.go
new file mode 100644
index 0000000..f1c96e0
--- /dev/null
+++ b/src/main.go
@@ -0,0 +1,16 @@
+package main
+
+import (
+	"flag"
+	"log"
+)
+
+func main() {
+	// parse the flags
+	registerHTTPFlags()
+	flag.Parse()
+
+	// setup the http server
+	httpServer := setupHTTPServer()
+	log.Fatalln(httpServer.ListenAndServe())
+}