From 1f230198467403faa7d8db0393f01ddfa3bf375c Mon Sep 17 00:00:00 2001 From: raul Date: Fri, 19 Apr 2024 07:51:21 +0200 Subject: [PATCH] Add http-server exercise --- httpserver/go.mod | 3 +++ httpserver/main.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 httpserver/go.mod create mode 100644 httpserver/main.go diff --git a/httpserver/go.mod b/httpserver/go.mod new file mode 100644 index 0000000..a40af2c --- /dev/null +++ b/httpserver/go.mod @@ -0,0 +1,3 @@ +module httpserver + +go 1.22.2 diff --git a/httpserver/main.go b/httpserver/main.go new file mode 100644 index 0000000..d119dbf --- /dev/null +++ b/httpserver/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func getRoot(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Received connection\n") + fmt.Fprintln(w, "Hello!") +} + +func main() { + http.HandleFunc("/", getRoot) + + err := http.ListenAndServe(":8080", nil) + if err != nil { + log.Fatal(err) + } +}