// Homework 31, challenge: A clear start error. // // When the server cannot start, it should print these two lines and then the // error itself: // Could not start the server on localhost:8080. // Is another copy still running? // // Keep the address in one constant, so that it is written only once, and use // the constant in both places. Test it by running the program in two terminals // at the same time. // // Run with: go run exercises/40/homework/04-clear-start-error.go package main import ( "fmt" "net/http" ) // TODO: add the constant for the address here. func handleHome(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Hello from Go!") } func main() { http.HandleFunc("/", handleHome) 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 { // TODO: replace this placeholder line with the clear error. fmt.Println("TODO: replace this line") } }