From c383e98bb8ff3915c656146efc6c85dd660609c4 Mon Sep 17 00:00:00 2001 From: cspark Date: Mon, 5 May 2025 20:42:36 +0100 Subject: [PATCH] Messing around with get methods and working with byte slices --- main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.go b/main.go index 562b83f..c061503 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io" "log" "net/http" "os" @@ -13,6 +14,7 @@ import ( func main() { http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) { fmt.Println("Hi, ", r.Header) + w.Write([]byte("Hi there!")) }) http_server := &http.Server{ @@ -26,6 +28,11 @@ func main() { log.Fatal(http_server.ListenAndServe()) }() fmt.Println("Server started! Listening in on ", http_server.Addr) + time.Sleep(1 * time.Second) + + resp, _ := http.Get("http://127.0.0.1:8080/foo") + body, _ := io.ReadAll(resp.Body) + fmt.Println(string(body)) sigs := make(chan os.Signal, 1) signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)