From 6877034698e6868110757cf53e8aa45164197467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ola=20Holmstr=C3=B6m?= Date: Fri, 10 Feb 2017 23:22:49 +0100 Subject: [PATCH] Add `HandleRequestWithKeys` so that `session.Keys` can be populated. Close #18. --- CHANGELOG.md | 5 +++++ melody.go | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e31f26d..0441908 100644 --- a/CHANGELOG.md +++ b/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. diff --git a/melody.go b/melody.go index 2af1624..1554acc 100644 --- a/melody.go +++ b/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,