olahol / melody

:notes: Minimalist websocket framework for Go
BSD 2-Clause "Simplified" License
3.75k stars 366 forks source link

support session.UnSet or delete #77

Closed idc77 closed 1 year ago

idc77 commented 1 year ago

In a fork of this when it was essentially abandoned someone contributed concurrency safety in a PR. This also had the session.UnSet() function

// UnSet will delete the key and has no return value
func (s *Session) UnSet(key string) {
    s.rwmutex.Lock()
    defer s.rwmutex.Unlock()
    if s.keys != nil {
        _, exists := s.keys[key]
        if exists {
            delete(s.keys, key)
        }
    }
}

Would you be willing to add this?

Because if you set e.g. a string to "" it's still set, the value is "" but when it's not in the keys, you get what I mean. p.s. correction, it was me who added that :D so, no copyright issue there.

Altough this is probably better

// UnSet will delete the key and has no return value
func (s *Session) UnSet(key string) {
    s.rwmutex.Lock()
    defer s.rwmutex.Unlock()
    if s.Keys != nil {
        _, exists := s.Keys[key]
        if exists {
            delete(s.Keys, key)
        }
    }
}

(Keys is pubic now)

olahol commented 1 year ago

That sounds like a good addition. If you make a PR I will merge it, that way you will show up on the contributors section.

idc77 commented 1 year ago

Thank you :)