// Homework 32, challenge: A small site. // // Write a helper function // writePage(w http.ResponseWriter, status int, title string, body string) // that sets the Content-Type, sets the status with w.WriteHeader, and writes a // whole HTML page with that title and body. Use it from three handlers: the // home page, /about, and a page of your own. Every page should have links to // the other two. // // Then make your own 404 page. The pattern "GET /" matches any GET path that no // other route matches, so a handler there can call writePage with // http.StatusNotFound. // // Run with: go run exercises/32/homework/04-small-site.go package main import ( "fmt" "net/http" ) func handleHome(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "TODO: replace this line") } // TODO: add writePage and the other handlers here. func main() { http.HandleFunc("GET /{$}", handleHome) // TODO: add the other routes here. 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) } }