From 217b6d72f4c1ecb7586ab51ff6fa6c3f010016b2 Mon Sep 17 00:00:00 2001 From: Emile Date: Fri, 18 Oct 2019 22:42:32 +0200 Subject: basic setup --- src/http.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/http.go (limited to 'src/http.go') 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") +} -- cgit 1.4.1