Browse Source

Add `HandleRequestWithKeys` so that `session.Keys` can be populated. Close #18.

master
Ola Holmström 8 years ago
parent
commit
6877034698
  1. 5
      CHANGELOG.md
  2. 7
      melody.go

5
CHANGELOG.md

@ -1,3 +1,8 @@
## 2017-02-10
* Return errors for some exposed methods.
* Add `HandleRequestWithKeys`.
## 2017-01-20
* Add `Len()` to fetch number of connected sessions.

7
melody.go

@ -81,6 +81,11 @@ func (m *Melody) HandleError(fn func(*Session, error)) {
// HandleRequest upgrades http requests to websocket connections and dispatches them to be handled by the melody instance.
func (m *Melody) HandleRequest(w http.ResponseWriter, r *http.Request) error {
return m.HandleRequestWithKeys(w, r, nil)
}
// 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 {
if m.hub.closed() {
return errors.New("Melody instance is closed.")
}
@ -93,7 +98,7 @@ func (m *Melody) HandleRequest(w http.ResponseWriter, r *http.Request) error {
session := &Session{
Request: r,
Keys: nil,
Keys: keys,
conn: conn,
output: make(chan *envelope, m.Config.MessageBufferSize),
melody: m,

Loading…
Cancel
Save