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

🤗 [Question]: Must Websocket Locals be read-only? #675

Closed
3 tasks done
supagroova opened this issue Jul 6, 2023 · 0 comments · Fixed by #676
Closed
3 tasks done

🤗 [Question]: Must Websocket Locals be read-only? #675

supagroova opened this issue Jul 6, 2023 · 0 comments · Fixed by #676
Labels
🤔 Question Further information is requested

Comments

@supagroova
Copy link
Contributor

Question Description

I notice that the Locals are read-only within the Websocket, and I was wonder if there is a reason for that?

I'm looking to persist user context through-out the length of the connection and was hoping to use Locals.

Would something like the below change be feasible? (I can submit a PR if so)

Code Snippet (optional)

// Locals makes it possible to pass interface{} values under string keys scoped to the request
// and therefore available to all following routes that match the request.
func (conn *Conn) Locals(key string, value ...interface{}) interface{} {
	if len(value) == 0 {
		return conn.locals[key]
	}
	conn.locals[key] = value[0]
	return value[0]
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
@supagroova supagroova added the 🤔 Question Further information is requested label Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant