```go
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
但是一运行就死锁了
更多评论
楼主好像对channel有一些误解.
你写的这个东西是无法处理通道的读写通讯的.
通道是等在那里的, 一旦写入就要有人读出, 否则就堵塞...
明白了么...
#1