1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00

MVC improvements: add HandleWebsocket that now registers events automatically based on the struct's methods(!) and fix a bug when more than one value of the same type is registered to a static field of a controller

Former-commit-id: e369d1426ac1a6b58314930a18362670317da3c1
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-07-09 12:16:19 +03:00
parent 85666da682
commit 450f20902d
18 changed files with 383 additions and 183 deletions

View File

@@ -68,7 +68,7 @@ func main() {
// serves the endpoint of ws://localhost:8080/echo
websocketRoute := app.Get("/echo", websocket.Handler(websocketServer))
j.Get()
if enableJWT {
// Register the jwt middleware (on handshake):
websocketRoute.Use(j.Serve)
@@ -76,20 +76,25 @@ func main() {
//
// Check for token through the jwt middleware
// on websocket connection or on any event:
/*
websocketServer.OnConnect = func(c *neffos.Conn) error {
ctx := websocket.GetContext(c)
if err := j.CheckJWT(ctx); err != nil {
// will send the above error on the client
// and will not allow it to connect to the websocket server at all.
return err
}
/* websocketServer.OnConnect = func(c *neffos.Conn) error {
ctx := websocket.GetContext(c)
if err := j.CheckJWT(ctx); err != nil {
// will send the above error on the client
// and will not allow it to connect to the websocket server at all.
return err
}
log.Printf("[%s] connected to the server", c.ID())
user := ctx.Values().Get("jwt").(*jwt.Token)
// or just: user := j.Get(ctx)
return nil
}
*/
log.Printf("This is an authenticated request\n")
log.Printf("Claim content:")
log.Printf("%#+v\n", user.Claims)
log.Printf("[%s] connected to the server", c.ID())
return nil
} */
}
// serves the browser-based websocket client.