Gin: SockJS integration

Created on 15 Nov 2014  ·  3Comments  ·  Source: gin-gonic/gin

Hi There,
I find it hard to integrate a sockjs server (http://godoc.org/gopkg.in/igm/sockjs-go.v2/sockjs) as the handler return an http.Handler type.

Here's the initializer:

var messageHandler = sockjs.NewHandler("/api/messages", sockjs.DefaultOptions, func(session sockjs.Session) {
    go func() {
        receiveMessage(session)
    }()
})

I can't just wrap it in a func (c *gin.Context) so I guess there's probably another way..?
Thanks for help.

Most helpful comment

51 issue and example works perfectly.

Thank you Javier!

For the sake of clarity for those interested:

func messageHandler(c *gin.Context) {
  sockjsHandler := sockjs.NewHandler("/api/messages", sockjs.DefaultOptions, func(session sockjs.Session) {
        go func() {
            receiveMessage(session)
        }()
    })
  sockjsHandler.ServeHTTP(c.Writer, c.Request)
}

All 3 comments

You can go to a lower level of the framework, please check this: #51

51 issue and example works perfectly.

Thank you Javier!

For the sake of clarity for those interested:

func messageHandler(c *gin.Context) {
  sockjsHandler := sockjs.NewHandler("/api/messages", sockjs.DefaultOptions, func(session sockjs.Session) {
        go func() {
            receiveMessage(session)
        }()
    })
  sockjsHandler.ServeHTTP(c.Writer, c.Request)
}

@gplume great, to avoid future issues like this, I'll update the readme soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atifzia picture atifzia  ·  3Comments

lilee picture lilee  ·  3Comments

nxvl picture nxvl  ·  3Comments

iiinsomnia picture iiinsomnia  ·  3Comments

rawoke083 picture rawoke083  ·  3Comments