Skip to content

Commit

Permalink
Use any instead of empty interface
Browse files Browse the repository at this point in the history
  • Loading branch information
olahol committed Mar 6, 2024
1 parent 3823d12 commit 4a98ad4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion melody.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -197,20 +197,20 @@ 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
}

// 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()

Expand All @@ -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
}
Expand Down

0 comments on commit 4a98ad4

Please sign in to comment.