From 0b39f1d1d375f808a276bc22b25680a724bfb716 Mon Sep 17 00:00:00 2001 From: Lachlan Laycock Date: Thu, 6 Jul 2023 14:05:30 +0200 Subject: [PATCH] Making Websocket Local read-write --- websocket/websocket.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/websocket/websocket.go b/websocket/websocket.go index 1d1519fb..57d1a463 100644 --- a/websocket/websocket.go +++ b/websocket/websocket.go @@ -172,8 +172,12 @@ func releaseConn(conn *Conn) { // 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) interface{} { - return conn.locals[key] +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] } // Params is used to get the route parameters.