diff --git a/melody.go b/melody.go index 00b1928..1342123 100644 --- a/melody.go +++ b/melody.go @@ -89,7 +89,7 @@ func New() *Melody { messageSentHandler: func(*Session, []byte) {}, messageSentHandlerBinary: func(*Session, []byte) {}, errorHandler: func(*Session, error) {}, - closeHandler: func(*Session, int, string) error { return nil }, + closeHandler: nil, connectHandler: func(*Session) {}, disconnectHandler: func(*Session) {}, pongHandler: func(*Session) {}, diff --git a/session.go b/session.go index 477fe83..3997cef 100644 --- a/session.go +++ b/session.go @@ -115,10 +115,11 @@ func (s *Session) readPump() { return nil }) - s.conn.SetCloseHandler(func(code int, text string) error { - s.melody.closeHandler(s, code, text) - return nil - }) + if s.melody.closeHandler != nil { + s.conn.SetCloseHandler(func(code int, text string) error { + return s.melody.closeHandler(s, code, text) + }) + } for { t, message, err := s.conn.ReadMessage()