github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2015/go4cpp/goodcounter.go (about) 1 // +build OMIT 2 3 package main 4 5 import ( 6 "fmt" 7 "log" 8 "net/http" 9 ) 10 11 var nextID = make(chan int) 12 13 func handler(w http.ResponseWriter, q *http.Request) { 14 fmt.Fprintf(w, "<h1>You got %v<h1>", <-nextID) 15 } 16 17 func counter() { 18 for i := 0; ; i++ { 19 nextID <- i 20 } 21 } 22 23 func main() { 24 http.HandleFunc("/", handler) 25 go counter() 26 log.Fatal(http.ListenAndServe("localhost:8080", nil)) 27 }