github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2015/go4cpp/battle.go (about)

     1  // +build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"net/http"
     8  )
     9  
    10  var battle = make(chan string)
    11  
    12  func handler(w http.ResponseWriter, q *http.Request) {
    13  	select {
    14  	case battle <- q.FormValue("usr"):
    15  		fmt.Fprintf(w, "You won!")
    16  	case won := <-battle:
    17  		fmt.Fprintf(w, "You lost, %v is better than you", won)
    18  	}
    19  }
    20  
    21  func main() {
    22  	http.HandleFunc("/fight", handler)
    23  	http.ListenAndServe("localhost:8080", nil)
    24  }