Skip to content

Websocket support proposal #106

Closed
wants to merge 2 commits into from

3 participants

@johnpmayer

To support this (#105)

func upgradeWebsocketHandler(wsHandler websocket.Handler) interface{} {
        return func(ctx *web.Context) {
                wsHandler.ServeHTTP(ctx.ResponseWriter, ctx.Request);
        }
}

Removed the interface type web.ResponseWriter and replaced with http.ResponseWriter

@johnpmayer

So the obvious downside here is the removal of web.ResponseWriter.Close(). Not sure how often this is used in real-world projects, anyone care to comment? If rewrites are possible, rw.Close() could just become Close(rw).

I imagine you ran into this at some point; I did while writing this change. However, I think that it's much nicer design to throw away the wrapper type and make Close a function, with the side effect of exposing the true ResponseWriter.

I am currently able to add websocket handlers to the server router via the method described in the OP.

s.Get(upgradeWebsocketHandler(websocket.Handle(foo)))
@robotamer

That is just a name

@hoisie
Owner
hoisie commented Apr 8, 2013

Yes! I really want websocket support. The 'Close' method was added because a very long time ago when Go had the concept of an HTTPConn which had a 'Close' method. Since then the ResponseWriter interface has gotten rid of it, so we can drop it too.

@hoisie
Owner
hoisie commented Apr 13, 2013

@johnpmayer Thanks for removing the web.ResponseWriter interface. I'm in the process of merging this.

@hoisie
Owner
hoisie commented Apr 13, 2013

Committed in 4b4df91. Thanks again!

@hoisie hoisie closed this Apr 13, 2013
@johnpmayer

Whoa awesome!

I'll test this out, and will try to share some of the ways I used your routers and upgraded websocket handlers. I just need to fine the relevant project :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.