// Homework 35, problem 2: A visit counter. // // GET / replies with "You are visitor number N.", and each request adds 1. Many // requests can arrive at the same time, so protect the count with a sync.Mutex. // Write a function nextVisit() int that does the locking. // // Run with: go run exercises/35/homework/02-visit-counter.go package main import ( "fmt" "net/http" ) // TODO: add the mutex, the count, and nextVisit here. func handleHome(w http.ResponseWriter, r *http.Request) { // TODO: write your code here, in place of this placeholder line: fmt.Fprintln(w, "TODO: replace this line") } func main() { http.HandleFunc("GET /{$}", 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 { fmt.Println("Server stopped:", err) } }