// Chapter 40 example: a server that shows each request it receives. // Run with: go run exercises/40/02-see-the-request.go // Then open http://localhost:8080/some/page in a browser. package main import ( "fmt" "net/http" ) func handleAll(w http.ResponseWriter, r *http.Request) { fmt.Printf("Request: %s %q\n", r.Method, r.URL.Path) fmt.Fprintf(w, "You sent %s for the path %s\n", r.Method, r.URL.Path) } func main() { http.HandleFunc("/", handleAll) fmt.Println("Server running at http://localhost:8080") fmt.Println("Press Ctrl+C to stop it.") err := http.ListenAndServe("localhost:8080", nil) if err != nil { fmt.Println("Server stopped:", err) } }