From d753975ae9c6c82c3569a48597ef752b85b4abc8 Mon Sep 17 00:00:00 2001 From: Emile Date: Wed, 6 Nov 2019 15:08:22 +0100 Subject: basic setup --- src/http.go | 35 +++++++++++++++++++++++++++++++++++ src/main.go | 16 ++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/http.go create mode 100644 src/main.go 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()) +} -- cgit 1.4.1