websocket icon indicating copy to clipboard operation
websocket copied to clipboard

Access to fiber.Ctx

Open GarryGaller opened this issue 3 years ago • 3 comments

How to access c.Locals ( where c is *fiber.Ctx) from a custom the websocket handler?

GarryGaller avatar Feb 20 '22 15:02 GarryGaller

https://github.com/gofiber/websocket/blob/master/README.md#example

Just check the example

ReneWerner87 avatar Feb 20 '22 21:02 ReneWerner87

This is not the c.Locals object I need. You need ctx.Locals, where cts is fiber.Ctx The c.Locals cannot have a value set. You can only read it.

GarryGaller avatar Feb 20 '22 21:02 GarryGaller

@GarryGaller I'm not completely sure what you aim to do. But here's an example where I bring fiber.Ctx into scope.

	app.Get("/ws/:id", func (ctx *fiber.Ctx) error {
		s := getSession(ctx)

		handler :=  websocket.New(func (c *websocket.Conn) {
			webSocketHandler(c, s)
		})

		return handler(ctx)
	})

Bastardly avatar Mar 30 '22 11:03 Bastardly