go-zero
go-zero copied to clipboard
w http.ResponseWriter cannot be casted to http.Flusher
trafficstars
gozero的Api的Handler层w http.ResponseWriter需要使用flush(),使用强制转换
f, ok := w.(http.Flusher)
没有用
但是使用http原生的http.ResponseWriter进行类型转换却可以转换w.(http.Flusher)
Which version are you using?
My test code is:
package main
import (
"io"
"net/http"
"github.com/zeromicro/go-zero/rest"
)
func main() {
srv := rest.MustNewServer(rest.RestConf{
Host: "localhost",
Port: 8888,
})
srv.Use(func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "from middleware\n")
next(w, r)
}
})
srv.AddRoute(rest.Route{
Method: http.MethodGet,
Path: "/hello",
Handler: func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "hello, world!")
f := w.(http.Flusher)
f.Flush()
},
})
defer srv.Stop()
srv.Start()
}
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.