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

This commit is contained in:
Ola Holmström
2017-02-10 23:22:49 +01:00
parent 3321ec3da7
commit 6877034698
2 changed files with 11 additions and 1 deletions
+5
View File
@@ -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.
+6 -1
View File
@@ -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,