package main import ( "fmt" "net/http" "sync" ) // mu protects visits. var mu sync.Mutex var visits = 0 func nextVisit() int { mu.Lock() defer mu.Unlock() visits = visits + 1 return visits } func handleHome(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "You are visitor number %d.\n", nextVisit()) } 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) } }