github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/go4java/goodcounter.go (about)

     1  // +build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"net/http"
     8  )
     9  
    10  var nextID = make(chan int)
    11  
    12  func handler(w http.ResponseWriter, q *http.Request) {
    13  	fmt.Fprintf(w, "<h1>You got %v<h1>", <-nextID)
    14  }
    15  
    16  func main() {
    17  	http.HandleFunc("/next", handler)
    18  	go func() {
    19  		for i := 0; ; i++ {
    20  			nextID <- i
    21  		}
    22  	}()
    23  	http.ListenAndServe("localhost:8080", nil)
    24  }