From 4a98ad4016b1a5f6f16daaaac5cdc4282861aa99 Mon Sep 17 00:00:00 2001 From: Ola <1386739+olahol@users.noreply.github.com> Date: Wed, 6 Mar 2024 18:35:41 +0100 Subject: [PATCH] Use any instead of empty interface --- melody.go | 2 +- session.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/melody.go b/melody.go index 673c787..5595585 100644 --- a/melody.go +++ b/melody.go @@ -146,7 +146,7 @@ func (m *Melody) HandleRequest(w http.ResponseWriter, r *http.Request) error { } // HandleRequestWithKeys does the same as HandleRequest but populates session.Keys with keys. -func (m *Melody) HandleRequestWithKeys(w http.ResponseWriter, r *http.Request, keys map[string]interface{}) error { +func (m *Melody) HandleRequestWithKeys(w http.ResponseWriter, r *http.Request, keys map[string]any) error { if m.hub.closed() { return ErrClosed } diff --git a/session.go b/session.go index 909dfc7..ed45ba0 100644 --- a/session.go +++ b/session.go @@ -12,7 +12,7 @@ import ( // Session wrapper around websocket connections. type Session struct { Request *http.Request - Keys map[string]interface{} + Keys map[string]any conn *websocket.Conn output chan envelope outputDone chan struct{} @@ -197,12 +197,12 @@ func (s *Session) CloseWithMsg(msg []byte) error { // Set is used to store a new key/value pair exclusively for this session. // It also lazy initializes s.Keys if it was not used previously. -func (s *Session) Set(key string, value interface{}) { +func (s *Session) Set(key string, value any) { s.rwmutex.Lock() defer s.rwmutex.Unlock() if s.Keys == nil { - s.Keys = make(map[string]interface{}) + s.Keys = make(map[string]any) } s.Keys[key] = value @@ -210,7 +210,7 @@ func (s *Session) Set(key string, value interface{}) { // Get returns the value for the given key, ie: (value, true). // If the value does not exists it returns (nil, false) -func (s *Session) Get(key string) (value interface{}, exists bool) { +func (s *Session) Get(key string) (value any, exists bool) { s.rwmutex.RLock() defer s.rwmutex.RUnlock() @@ -222,7 +222,7 @@ func (s *Session) Get(key string) (value interface{}, exists bool) { } // MustGet returns the value for the given key if it exists, otherwise it panics. -func (s *Session) MustGet(key string) interface{} { +func (s *Session) MustGet(key string) any { if value, exists := s.Get(key); exists { return value }