about summary refs log tree commit diff
path: root/src/http.go
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-18 22:42:32 +0200
committerEmile <hanemile@protonmail.com>2019-10-18 22:42:32 +0200
commit217b6d72f4c1ecb7586ab51ff6fa6c3f010016b2 (patch)
treee14b0966061eba9c3ddcebb78767918e9ab18ec4 /src/http.go
parent02e63b59571e356ab36b67c456b88c524241ccc6 (diff)
basic setup
Diffstat (limited to 'src/http.go')
-rw-r--r--src/http.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/http.go b/src/http.go
new file mode 100644
index 0000000..a813ae6
--- /dev/null
+++ b/src/http.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+	"net/http"
+
+	"github.com/gorilla/mux"
+)
+
+var (
+	port *int
+)
+
+func registerHTTPFlags() {
+	port = flag.Int("port", 8080, "The port for HTTP")
+}
+
+func setupHTTPServer() http.Server {
+	r := mux.NewRouter()
+
+	r.HandleFunc("/", indexHandler)
+
+	return http.Server{
+		Addr:    fmt.Sprintf("0.0.0.0:%d", *port),
+		Handler: r,
+	}
+}
+
+// Host the index file
+func indexHandler(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "%s", "Hello World!\n")
+}