cherrySession

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Init = iota
	WaitAck
	Working
	Closed
)

Variables

This section is empty.

Functions

func AddOnCloseListener

func AddOnCloseListener(listener ...SessionListener)

func AddOnCreateListener

func AddOnCreateListener(listener ...SessionListener)

func AddOnDataListener

func AddOnDataListener(listener ...SessionListener)

func Bind

func Bind(sid cfacade.SID, uid cfacade.UID) error

func CloseAll

func CloseAll(cb func(session *Session))

func ForEachSIDSession

func ForEachSIDSession(fn func(s *Session))

func ForEachUIDSession

func ForEachUIDSession(fn func(s *Session))

func GetSessionCount

func GetSessionCount() int

func Kick

func Kick(uid cfacade.UID) error

func KickBySID

func KickBySID(sid cfacade.SID) error

func NextSID

func NextSID() cfacade.SID

func Unbind

func Unbind(sid cfacade.SID)

Types

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group represents a session group which used to manage a number of sessions, data send to the group will send to all session in it.

func NewGroup

func NewGroup(n string) *Group

NewGroup returns a new group instance

func (*Group) Add

func (c *Group) Add(session *Session) error

Add add session to group

func (*Group) Broadcast

func (c *Group) Broadcast(route string, v interface{}) error

Broadcast push the message(s) to all members

func (*Group) Close

func (c *Group) Close() error

Close destroy group, which will release all resource in the group

func (*Group) Contains

func (c *Group) Contains(uid int64) bool

Contains check whether a UID is contained in current group or not

func (*Group) Count

func (c *Group) Count() int

Count get current member amount in the group

func (*Group) Leave

func (c *Group) Leave(s *Session) error

Leave remove specified UID related session from group

func (*Group) LeaveAll

func (c *Group) LeaveAll() error

LeaveAll clear all sessions in the group

func (*Group) Member

func (c *Group) Member(uid int64) (*Session, error)

Member returns specified UID's session

func (*Group) Members

func (c *Group) Members() []int64

Members returns all member's UID in current group

func (*Group) Multicast

func (c *Group) Multicast(route string, v interface{}, filter SessionFilter) error

Multicast push the message to the filtered clients

type Session

type Session struct {
	// contains filtered or unexported fields
}

func Create

func Create(sid cfacade.SID, frontendId cfacade.FrontendId, network cfacade.INetwork) *Session

func FakeSession

func FakeSession(request *cproto.Request, network cfacade.INetwork) *Session

func GetBySID

func GetBySID(sid cfacade.SID) (*Session, bool)

func GetByUID

func GetByUID(uid cfacade.UID) (*Session, bool)

func NewSession

func NewSession(sid cfacade.SID, frontendId cfacade.FrontendId, network cfacade.INetwork) *Session

func (*Session) Clear

func (s *Session) Clear()

Clear releases all settings related to current sc

func (*Session) Close

func (s *Session) Close()

func (*Session) Contains

func (s *Session) Contains(key string) bool

func (*Session) Data

func (s *Session) Data() map[string]string

func (*Session) Debug

func (s *Session) Debug(args ...interface{})

func (*Session) Debugf

func (s *Session) Debugf(template string, args ...interface{})

func (*Session) Error

func (s *Session) Error(args ...interface{})

func (*Session) Errorf

func (s *Session) Errorf(template string, args ...interface{})

func (*Session) FrontendId

func (s *Session) FrontendId() cfacade.FrontendId

func (*Session) GetInt

func (s *Session) GetInt(key string) int

func (*Session) GetInt32

func (s *Session) GetInt32(key string) int32

GetInt32 returns the value associated with the key as a int32.

func (*Session) GetInt64

func (s *Session) GetInt64(key string) int64

GetInt64 returns the value associated with the key as a int64.

func (*Session) GetString

func (s *Session) GetString(key string) string

GetString returns the value associated with the key as a string.

func (*Session) ImportAll

func (s *Session) ImportAll(settings map[string]string)

func (*Session) Info

func (s *Session) Info(args ...interface{})

func (*Session) Infof

func (s *Session) Infof(template string, args ...interface{})

func (*Session) IsBind

func (s *Session) IsBind() bool

func (*Session) Kick

func (s *Session) Kick(reason interface{}, close bool)

func (*Session) LogEnable

func (s *Session) LogEnable(level zapcore.Level) bool

func (*Session) OnCloseListener

func (s *Session) OnCloseListener()

func (*Session) OnDataListener

func (s *Session) OnDataListener() bool

func (*Session) Push

func (s *Session) Push(route string, v interface{})

Push message to client

func (*Session) RPC

func (s *Session) RPC(nodeId string, route string, req proto.Message, rsp proto.Message) int32

RPC sends message to remote server

func (*Session) RemoteAddress

func (s *Session) RemoteAddress() string

func (*Session) Remove

func (s *Session) Remove(key string)

func (*Session) Response

func (s *Session) Response(ctx context.Context, v interface{}, isError ...bool)

func (*Session) ResponseMID

func (s *Session) ResponseMID(mid uint, v interface{}, isError ...bool)

ResponseMID responses message to client, mid is request message ID

func (*Session) Restore

func (s *Session) Restore(data map[string]string)

func (*Session) SID

func (s *Session) SID() cfacade.SID

func (*Session) SendRaw

func (s *Session) SendRaw(bytes []byte)

func (*Session) Set

func (s *Session) Set(key string, value string)

func (*Session) SetState

func (s *Session) SetState(state int32)

func (*Session) State

func (s *Session) State() int32

func (*Session) String

func (s *Session) String() string

func (*Session) UID

func (s *Session) UID() cfacade.UID

func (*Session) Warn

func (s *Session) Warn(args ...interface{})

func (*Session) Warnf

func (s *Session) Warnf(template string, args ...interface{})

type SessionFilter

type SessionFilter func(*Session) bool

SessionFilter represents a filter which was used to filter session when Multicast, the session will receive the message while filter returns true.

type SessionListener

type SessionListener func(session *Session) (next bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL