我正在使用 go 1.4.2 并且实现似乎没有 CloseNotifier
因为我想在长轮询处理程序中使用它,例如:
func Pollhandler(w http.ResponseWriter, r *http.Request) {
notify := w.(CloseNotifier).CloseNotify()
<-notify //should block until the http connection is closed
}
是否没有为 http ResponseWriter
实现 CloseNotifier?如果是这样,我该如何解决这个问题?或者是否有任何实现 CloseNotifier
接口(interface)的 http ResponseWriter
实现?
最佳答案
http.CloseNotifier
自 Go 1.1 以来一直存在.您的代码不起作用,因为您忘记了包部分:
notify := w.(http.CloseNotifier).CloseNotify()
关于go - http ResponseWriter 的 CloseNotifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32651999/