package main import ( "fmt" "io" "net/http" ) func helloHandler(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("Hello, World!")) } func requestServer() { resp, err := http.Get("http://localhost:8080") fmt.Println(err) defer resp.Body.Close() body, err := io.ReadAll(resp.Body) fmt.Printf("\nWebserver said: `%s`", string(body)) } func main() { http.HandleFunc("/", helloHandler) go func() { err := http.ListenAndServe(":8080", nil) fmt.Println(err) // don't ignore errors }() requestServer() }