package main import ( "fmt" "net/http" "strconv" ) func handleDouble(w http.ResponseWriter, r *http.Request) { n, err := strconv.Atoi(r.PathValue("n")) if err != nil { http.Error(w, "The path must end in a whole number.", http.StatusBadRequest) return } if n < -1000000 || n > 1000000 { http.Error(w, "The number must be from -1000000 to 1000000.", http.StatusBadRequest) return } fmt.Fprintf(w, "%d doubled is %d\n", n, n*2) } func main() { http.HandleFunc("GET /double/{n}", handleDouble) 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) } }