Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SockJS integration #150

Closed
gplume opened this issue Nov 15, 2014 · 3 comments
Closed

SockJS integration #150

gplume opened this issue Nov 15, 2014 · 3 comments
Assignees

Comments

@gplume
Copy link

gplume commented Nov 15, 2014

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.

@javierprovecho
Copy link
Member

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

@gplume
Copy link
Author

gplume commented Nov 15, 2014

#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 gplume closed this as completed Nov 15, 2014
@javierprovecho javierprovecho self-assigned this Nov 16, 2014
@javierprovecho
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants