Documentation ¶
Index ¶
- Variables
- func OnAfterSessionBind(f func(ctx context.Context, s *Session) error)
- func OnSessionBind(f func(ctx context.Context, s *Session) error)
- func OnSessionClose(f func(s *Session))
- type HandshakeClientData
- type HandshakeData
- type NetworkEntity
- type Session
- func (s *Session) Bind(ctx context.Context, uid string) error
- func (s *Session) Clear()
- func (s *Session) Close()
- func (s *Session) Float32(key string) float32
- func (s *Session) Float64(key string) float64
- func (s *Session) Get(key string) interface{}
- func (s *Session) GetData() map[string]interface{}
- func (s *Session) GetDataEncoded() []byte
- func (s *Session) GetHandshakeData() *HandshakeData
- func (s *Session) HasKey(key string) bool
- func (s *Session) ID() int64
- func (s *Session) Int(key string) int
- func (s *Session) Int16(key string) int16
- func (s *Session) Int32(key string) int32
- func (s *Session) Int64(key string) int64
- func (s *Session) Int8(key string) int8
- func (s *Session) Kick(ctx context.Context) error
- func (s *Session) OnClose(c func()) error
- func (s *Session) Push(route string, v interface{}) error
- func (s *Session) PushToFront(ctx context.Context) error
- func (s *Session) RemoteAddr() net.Addr
- func (s *Session) Remove(key string) error
- func (s *Session) ResponseMID(ctx context.Context, mid uint, v interface{}, err ...bool) error
- func (s *Session) Set(key string, value interface{}) error
- func (s *Session) SetData(data map[string]interface{}) error
- func (s *Session) SetDataEncoded(encodedData []byte) error
- func (s *Session) SetFrontendData(frontendID string, frontendSessionID int64)
- func (s *Session) SetHandshakeData(data *HandshakeData)
- func (s *Session) String(key string) string
- func (s *Session) UID() string
- func (s *Session) Uint(key string) uint
- func (s *Session) Uint16(key string) uint16
- func (s *Session) Uint32(key string) uint32
- func (s *Session) Uint64(key string) uint64
- func (s *Session) Uint8(key string) uint8
- func (s *Session) Value(key string) interface{}
Constants ¶
This section is empty.
Variables ¶
var ( // SessionCloseCallbacks contains global session close callbacks SessionCloseCallbacks = make([]func(s *Session), 0) // SessionCount keeps the current number of sessions SessionCount int64 )
Functions ¶
func OnAfterSessionBind ¶
OnAfterSessionBind adds a method to be called when session is bound and after all sessionBind callbacks
func OnSessionBind ¶
OnSessionBind adds a method to be called when a session is bound same function cannot be added twice!
func OnSessionClose ¶
func OnSessionClose(f func(s *Session))
OnSessionClose adds a method that will be called when every session closes
Types ¶
type HandshakeClientData ¶
type HandshakeClientData struct { Platform string `json:"platform"` LibVersion string `json:"libVersion"` BuildNumber string `json:"clientBuildNumber"` Version string `json:"clientVersion"` }
HandshakeClientData represents information about the client sent on the handshake.
type HandshakeData ¶
type HandshakeData struct { Sys HandshakeClientData `json:"sys"` User map[string]interface{} `json:"user,omitempty"` }
HandshakeData represents information about the handshake sent by the client. `sys` corresponds to information independent from the app and `user` information that depends on the app and is customized by the user.
type NetworkEntity ¶
type NetworkEntity interface { Push(route string, v interface{}) error ResponseMID(ctx context.Context, mid uint, v interface{}, isError ...bool) error Close() error Kick(ctx context.Context) error RemoteAddr() net.Addr SendRequest(ctx context.Context, serverID, route string, v interface{}) (*protos.Response, error) }
NetworkEntity represent low-level network instance
type Session ¶
type Session struct { sync.RWMutex // protect data OnCloseCallbacks []func() //onClose callbacks IsFrontend bool // if session is a frontend session Subscriptions []*nats.Subscription // subscription created on bind when using nats rpc server // contains filtered or unexported fields }
Session represents a client session, which can store data during the connection. All data is released when the low-level connection is broken. Session instance related to the client will be passed to Handler method in the context parameter.
func GetSessionByID ¶
GetSessionByID return a session bound to a frontend server id
func GetSessionByUID ¶
GetSessionByUID return a session bound to an user id
func New ¶
func New(entity NetworkEntity, frontend bool, UID ...string) *Session
New returns a new session instance a NetworkEntity is a low-level network instance
func (*Session) Clear ¶
func (s *Session) Clear()
Clear releases all data related to current session
func (*Session) Close ¶
func (s *Session) Close()
Close terminates current session, session related data will not be released, all related data should be cleared explicitly in Session closed callback
func (*Session) GetDataEncoded ¶
GetDataEncoded returns the session data as an encoded value
func (*Session) GetHandshakeData ¶
func (s *Session) GetHandshakeData() *HandshakeData
GetHandshakeData gets the handshake data received by the client.
func (*Session) OnClose ¶
OnClose adds the function it receives to the callbacks that will be called when the session is closed
func (*Session) PushToFront ¶
PushToFront updates the session in the frontend
func (*Session) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Session) ResponseMID ¶
ResponseMID responses message to client, mid is request message ID
func (*Session) SetDataEncoded ¶
SetDataEncoded sets the whole session data from an encoded value
func (*Session) SetFrontendData ¶
SetFrontendData sets frontend id and session id
func (*Session) SetHandshakeData ¶
func (s *Session) SetHandshakeData(data *HandshakeData)
SetHandshakeData sets the handshake data received by the client.