Added params to session
This commit is contained in:
@@ -80,6 +80,7 @@ func (m *Melody) HandleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
session := &Session{
|
session := &Session{
|
||||||
Request: r,
|
Request: r,
|
||||||
|
params: make(map[string]string),
|
||||||
conn: conn,
|
conn: conn,
|
||||||
output: make(chan *envelope, m.Config.MessageBufferSize),
|
output: make(chan *envelope, m.Config.MessageBufferSize),
|
||||||
melody: m,
|
melody: m,
|
||||||
|
|||||||
+11
@@ -10,6 +10,7 @@ import (
|
|||||||
// A melody session.
|
// A melody session.
|
||||||
type Session struct {
|
type Session struct {
|
||||||
Request *http.Request
|
Request *http.Request
|
||||||
|
params map[string]string
|
||||||
conn *websocket.Conn
|
conn *websocket.Conn
|
||||||
output chan *envelope
|
output chan *envelope
|
||||||
melody *Melody
|
melody *Melody
|
||||||
@@ -117,3 +118,13 @@ func (s *Session) WriteBinary(msg []byte) {
|
|||||||
func (s *Session) Close() {
|
func (s *Session) Close() {
|
||||||
s.writeMessage(&envelope{t: websocket.CloseMessage, msg: []byte{}})
|
s.writeMessage(&envelope{t: websocket.CloseMessage, msg: []byte{}})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set session param
|
||||||
|
func (s *Session) SetParam(key string, value string) {
|
||||||
|
s.params[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get session param
|
||||||
|
func (s *Session) GetParam(key string) string {
|
||||||
|
return s.params[key]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user