Closed RhaPT closed 1 day ago
Thanks for opening your first issue here! š Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
@RhaPT First you never call init()
. Second, the values from the context are only valid during the handler execution.
Here:
func setXpto(c *fiber.Ctx) error {
xID := c.Get("X-Id", "")
Xpto[xID] = xID
log.Println(Xpto)
c.Status(fiber.StatusOK)
return c.JSON(Xpto)
}
You have to copy the value form the context like this:
xID := utils.CopyString(c.Get("X-Id", ""))
Documentation is here: https://docs.gofiber.io/#zero-allocation
@RhaPT Did that fix your issue?
Thanks for your help
Awesome šŖ
Question Description
Sorry about my English. I created a page with javascript where it creates a websocket and receives a unique id ("Sec-Websocket-Key") for that instance, then it uses this id whenever it makes a request to the api (sends in the header an X-Id with this value), the api stores data within a map indexed by X-Id
If you open another window in the same browser (if use other browser no problem) and call the same page, it will create a new instance for in websocket and at that time it automatically changes the MAP.
Example the first time you open the page: map[] after adding a value : map[GlYkSNQ6GQMFtdkHGqlxZw==:GlYkSNQ6GQMFtdkHGqlxZw==] after open new window in same browser: map[keep-aliveMFtdkHGqlxZw==:keep-aliveMFtdkHGqlxZw==]
Does anyone know why the Map changes?
Code Snippet (optional)
Checklist: