Allow sending custom close messages
This commit is contained in:
+14
-1
@@ -2,10 +2,11 @@ package melody
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// Session wrapper around websocket connections.
|
||||
@@ -165,6 +166,18 @@ func (s *Session) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CloseWithMsg closes the session with the provided payload.
|
||||
// Use the FormatCloseMessage function to format a proper close message payload.
|
||||
func (s *Session) CloseWithMsg(msg []byte) error {
|
||||
if s.closed() {
|
||||
return errors.New("Session is already closed.")
|
||||
}
|
||||
|
||||
s.writeMessage(&envelope{t: websocket.CloseMessage, msg: msg})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set is used to store a new key/value pair exclusivelly for this session.
|
||||
// It also lazy initializes s.Keys if it was not used previously.
|
||||
func (s *Session) Set(key string, value interface{}) {
|
||||
|
||||
Reference in New Issue
Block a user