package main
import "net/http"
func main() {
c := make(chan string)
http.HandleFunc("/get", func(w http.ResponseWriter, r *http.Request) {
msg,_ := <- c
w.Write([]byte(msg))
})
http.HandleFunc("/post", func(w http.ResponseWriter, r *http.Request) {
c <- "world"
w.Write([]byte(" world!"))
})
http.ListenAndServe("localhost:3000", nil)
}
期望 curl http://localhost:3000/post 写channel curl http://localhost:3000/get 读channel 但是一运行就死锁了