From c7571d2e8195bc5e4a7187f3eac47c5094931e3e Mon Sep 17 00:00:00 2001 From: efim Date: Fri, 27 Oct 2023 06:04:31 +0000 Subject: [PATCH] init: server start --- main.go | 17 +++++++++++++++-- routes/routes.go | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 routes/routes.go diff --git a/main.go b/main.go index e2e619d..c20668a 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,20 @@ package main -import "fmt" +import ( + "flag" + "fmt" + "log" + "net/http" + "sunshine.industries/some-automoderation/routes" +) func main() { - fmt.Println("hi, please") + var port int + flag.IntVar(&port, "port", 8080, "Port on which the server should start") + flag.Parse() + + fmt.Printf("Server will start on port %d", port) + routes.RegisterRoutes() + + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) } diff --git a/routes/routes.go b/routes/routes.go new file mode 100644 index 0000000..7da917b --- /dev/null +++ b/routes/routes.go @@ -0,0 +1,15 @@ +package routes + +import ( + "fmt" + "net/http" +) + +func RegisterRoutes() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + someString := "hello" + someNum := 123 + fmt.Fprintf(w, "A response, with values %s and %d", someString, someNum) + }) + +}