Use any instead of empty interface

This commit is contained in:
Ola
2024-03-06 18:35:41 +01:00
parent 3823d1271f
commit 4a98ad4016
2 changed files with 6 additions and 6 deletions
+1 -1
View File
@@ -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. // 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() { if m.hub.closed() {
return ErrClosed return ErrClosed
} }
+5 -5
View File
@@ -12,7 +12,7 @@ import (
// Session wrapper around websocket connections. // Session wrapper around websocket connections.
type Session struct { type Session struct {
Request *http.Request Request *http.Request
Keys map[string]interface{} Keys map[string]any
conn *websocket.Conn conn *websocket.Conn
output chan envelope output chan envelope
outputDone chan struct{} 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. // 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. // 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() s.rwmutex.Lock()
defer s.rwmutex.Unlock() defer s.rwmutex.Unlock()
if s.Keys == nil { if s.Keys == nil {
s.Keys = make(map[string]interface{}) s.Keys = make(map[string]any)
} }
s.Keys[key] = value 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). // Get returns the value for the given key, ie: (value, true).
// If the value does not exists it returns (nil, false) // 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() s.rwmutex.RLock()
defer s.rwmutex.RUnlock() 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. // 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 { if value, exists := s.Get(key); exists {
return value return value
} }