mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
Replace websocket->Values() with ->SetValue/GetValue instead.
Former-commit-id: fe7fa1a40123b34ec864732ddfee796574cefa72
This commit is contained in:
parent
068b571183
commit
31b804d90b
|
@ -143,8 +143,6 @@ type (
|
|||
// websocket has everything you need to authenticate the user BUT if it's necessary
|
||||
// then you use it to receive user information, for example: from headers
|
||||
Context() *iris.Context
|
||||
// Values returns the temporary lock-free connection's data store
|
||||
Values() ConnectionValues
|
||||
|
||||
// OnDisconnect registers a callback which fires when this connection is closed by an error or manual
|
||||
OnDisconnect(DisconnectFunc)
|
||||
|
@ -176,6 +174,16 @@ type (
|
|||
// Disconnect disconnects the client, close the underline websocket conn and removes it from the conn list
|
||||
// returns the error, if any, from the underline connection
|
||||
Disconnect() error
|
||||
// SetValue sets a key-value pair on the connection's mem store.
|
||||
SetValue(key string, value interface{})
|
||||
// GetValue gets a value by its key from the connection's mem store.
|
||||
GetValue(key string) interface{}
|
||||
// GetValueArrString gets a value as []string by its key from the connection's mem store.
|
||||
GetValueArrString(key string) []string
|
||||
// GetValueString gets a value as string by its key from the connection's mem store.
|
||||
GetValueString(key string) string
|
||||
// GetValueInt gets a value as integer by its key from the connection's mem store.
|
||||
GetValueInt(key string) int
|
||||
}
|
||||
|
||||
connection struct {
|
||||
|
@ -468,3 +476,44 @@ func (c *connection) fireOnLeave(roomName string) {
|
|||
func (c *connection) Disconnect() error {
|
||||
return c.server.Disconnect(c.ID())
|
||||
}
|
||||
|
||||
// mem per-conn store
|
||||
|
||||
func (c *connection) SetValue(key string, value interface{}) {
|
||||
c.values.Set(key, value)
|
||||
}
|
||||
|
||||
func (c *connection) GetValue(key string) interface{} {
|
||||
return c.values.Get(key)
|
||||
}
|
||||
|
||||
func (c *connection) GetValueArrString(key string) []string {
|
||||
if v := c.values.Get(key); v != nil {
|
||||
if arrString, ok := v.([]string); ok {
|
||||
return arrString
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *connection) GetValueString(key string) string {
|
||||
if v := c.values.Get(key); v != nil {
|
||||
if s, ok := v.(string); ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *connection) GetValueInt(key string) int {
|
||||
if v := c.values.Get(key); v != nil {
|
||||
if i, ok := v.(int); ok {
|
||||
return i
|
||||
} else if s, ok := v.(string); ok {
|
||||
if iv, err := strconv.Atoi(s); err == nil {
|
||||
return iv
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user