rw.(http.Flusher) doesn't return error, but Flush() doesn't work

214 views
Skip to first unread message

Nikita Loskutov

unread,
Oct 13, 2014, 7:24:26 AM10/13/14
to golan...@googlegroups.com
Hello!
I'm trying to develop something like simple chat.

I have code:
func watch(rw http.ResponseWriter, r render.Render) {
var msg string
ok := true
for ok {
select {
case msg, ok = <-Ct.Msgs:
rw.Write([]byte(msg))
fmt.Printf("Wrote: %v", msg)
f, ok := rw.(http.Flusher)
if ok {
f.Flush()
fmt.Println("Flushed")
} else {
r.JSON(http.StatusOK, Response{"status": "error", "descr": "CANT_FLUSH"})
return
}
}
}

r.JSON(http.StatusOK, Response{"status": "ok", "descr": "finished"})
}

In log I have:
    Wrote: hello
    Flushed

But I see nothing in my browser.

Full code:

What's wrong and why?

Thx

Robert Melton

unread,
Oct 13, 2014, 9:38:53 AM10/13/14
to Nikita Loskutov, golang-nuts
Check the error code from rs.Write
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Robert Melton | http://robertmelton.com
Reply all
Reply to author
Forward
0 new messages