Add HandleRequestWithKeys so that session.Keys can be populated. Close #18.
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
## 2017-02-10
|
||||||
|
|
||||||
|
* Return errors for some exposed methods.
|
||||||
|
* Add `HandleRequestWithKeys`.
|
||||||
|
|
||||||
## 2017-01-20
|
## 2017-01-20
|
||||||
|
|
||||||
* Add `Len()` to fetch number of connected sessions.
|
* Add `Len()` to fetch number of connected sessions.
|
||||||
|
|||||||
@@ -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.
|
// 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 {
|
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() {
|
if m.hub.closed() {
|
||||||
return errors.New("Melody instance is 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{
|
session := &Session{
|
||||||
Request: r,
|
Request: r,
|
||||||
Keys: nil,
|
Keys: keys,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
output: make(chan *envelope, m.Config.MessageBufferSize),
|
output: make(chan *envelope, m.Config.MessageBufferSize),
|
||||||
melody: m,
|
melody: m,
|
||||||
|
|||||||
Reference in New Issue
Block a user