gpt4 book ai didi

go - http ResponseWriter 的 CloseNotifier

转载 作者:IT王子 更新时间:2023-10-29 02:33:52 27 4
gpt4 key购买 nike

我正在使用 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.CloseNotifierGo 1.1 以来一直存在.您的代码不起作用,因为您忘记了包部分:

notify := w.(http.CloseNotifier).CloseNotify()

关于go - http ResponseWriter 的 CloseNotifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32651999/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com