From 54d1f91e7e260442dbcc151952dd58a689c600be Mon Sep 17 00:00:00 2001 From: Muyao CHEN Date: Wed, 26 Jun 2024 17:30:39 +0200 Subject: [PATCH] Hello world --- cmd/hello-world/main.go | 18 ++++++++++++++++++ go.mod | 3 +++ 2 files changed, 21 insertions(+) create mode 100644 cmd/hello-world/main.go create mode 100644 go.mod diff --git a/cmd/hello-world/main.go b/cmd/hello-world/main.go new file mode 100644 index 0000000..87ca56e --- /dev/null +++ b/cmd/hello-world/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "net/http" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + n, err := fmt.Fprintf(w, "Hello world") + if err != nil { + fmt.Println(err) + } + fmt.Printf("Number of bytes written: %d\n", n) + }) + + _ = http.ListenAndServe(":8080", nil) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6c69ec1 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go-udemy-web-1 + +go 1.21.0