From da44e942b3c8588ba820a81ffbdec6f887c4e7b5 Mon Sep 17 00:00:00 2001 From: Quinta <0pietroquintavalle0@gmail.com> Date: Fri, 19 Jul 2024 17:37:54 +0200 Subject: [PATCH] Very very crude HTTP server --- .idea/.gitignore | 8 +++++++ .idea/git_toolbox_blame.xml | 6 +++++ .idea/httpserver.iml | 9 ++++++++ .idea/material_theme_project_new.xml | 13 +++++++++++ .idea/modules.xml | 8 +++++++ .idea/vcs.xml | 6 +++++ main.go | 33 ++++++++++++++++++++++++++++ 7 files changed, 83 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/git_toolbox_blame.xml create mode 100644 .idea/httpserver.iml create mode 100644 .idea/material_theme_project_new.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 main.go diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/git_toolbox_blame.xml b/.idea/git_toolbox_blame.xml new file mode 100644 index 0000000..7dc1249 --- /dev/null +++ b/.idea/git_toolbox_blame.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/httpserver.iml b/.idea/httpserver.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/httpserver.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..9fac092 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..259cee6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..7e182b4 --- /dev/null +++ b/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "errors" + "fmt" + "io" + "net/http" + "os" +) + +func getRoot(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Request received: \n") + io.WriteString(w, "This is my first web server. \n") +} + +func getHello(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Hello request received: \n") + io.WriteString(w, "Hello, World! \n") +} + +func main() { + http.HandleFunc("/", getRoot) + http.HandleFunc("/hello", getHello) + + err := http.ListenAndServe(":8080", nil) + if errors.Is(err, http.ErrServerClosed) { + fmt.Printf("Server Closed! \n") + } else if err != nil { + fmt.Printf("Error: %v \n", err) + os.Exit(1) + } + fmt.Printf("Server started! \n") +}