Documentation
¶
Index ¶
- Constants
- Variables
- func AddResEventType(ev EventType)
- func BuildConn(url string, head http.Header, resp func(resp *http.Response), ...) (*websocket.Conn, error)
- func BytesToString(b []byte) string
- func DefaultRespInterceptor(req *EventReq) bool
- func IsClientEvent(ev int32) bool
- func IsEventType(ev int32) int32
- func IsExServerEvent(ev int32) bool
- func IsMQEvent(ev int32) bool
- func IsServerEvent(ev int32) bool
- func IsUserStatusChanged(ev int32) bool
- func NewContext(ctx context.Context, traceId string) context.Context
- func NewWithTraceId(traceId string) context.Context
- func PBSessionToSession(pb *pb.Session) session.Session
- func PBUserToSession(u *pb.User) session.Session
- func Quote(d interface{}) string
- func RemoveResEventType(ev EventType)
- func SdkVersion() string
- func SessionToPBSession(se *session.Session, token string) *pb.Session
- func SessionToPBUser(session *session.Session) *pb.User
- func StringEvent(e int32) string
- func StringToBytes(s string) []byte
- func ToPBEvent(ev *Event) *pb.Event
- func WithHeartbeatDuration(t time.Duration) option.Option
- type Action
- type Alarm
- type AlarmFunc
- type Attribute
- type Body
- type Client
- type Config
- type Connect
- func (c *Connect) AddSession(key string, se *session.Session)
- func (c *Connect) Close(ctx context.Context, reason string) error
- func (c *Connect) Enter(ctx context.Context, user *session.Session, loginTime int64)
- func (c *Connect) GetAddr() string
- func (c *Connect) GetConnectId() uint64
- func (c *Connect) GetConnectTime() int64
- func (c *Connect) GetHeartTime() int64
- func (c *Connect) GetIndex() int64
- func (c *Connect) GetRemoteIP() string
- func (c *Connect) GetSessionKey(fn func(s *session.Session) string) []string
- func (c *Connect) GetSource() string
- func (c *Connect) GetSyncTime() int64
- func (c *Connect) HasSession() int
- func (c *Connect) IsClosed() bool
- func (c *Connect) Leave(ctx context.Context, user *session.Session, logoutTime int64)
- func (c *Connect) RemoveSession(key string) int
- func (c *Connect) Run()
- func (c *Connect) SendMQ(ctx context.Context, session *session.Session, topic string, content string) error
- func (c *Connect) SendTo(msg []byte) error
- func (c *Connect) SendToQueue(ctx context.Context, msg []byte) error
- func (c *Connect) String() string
- func (c *Connect) Subscribe(ctx context.Context, session *session.Session, topic ...string) error
- func (c *Connect) UnSubscribe(ctx context.Context, session *session.Session, topic ...string) error
- type ConnectCmd
- type Copy
- type DisposeInterceptor
- type Event
- type EventReq
- type EventRes
- type EventType
- type FromMemberFunc
- type Handler
- type Hub
- func (hub *Hub) AddConnect(conn *Connect)
- func (hub *Hub) AddUser(userKey string, client *UserClient)
- func (hub *Hub) Alarm(ctx context.Context, code int32, level int32, title, detail string, err error)
- func (hub *Hub) CheckAllUserOnline(ctx context.Context, session *session.Session) bool
- func (hub *Hub) CheckUserOnline(ctx context.Context, se *session.Session) bool
- func (hub *Hub) ConnectQuery(f func(client *Connect) (result bool))
- func (hub *Hub) ConnectSearch(q Query) []*Connect
- func (hub *Hub) DelConnect(conn *Connect)
- func (hub *Hub) DelUser(ctx context.Context, user *session.Session, conn *Connect) bool
- func (hub *Hub) GetAllUserList(ctx context.Context, session *session.Session) *UserList
- func (hub *Hub) GetAppList() []string
- func (hub *Hub) GetConnects() []*Connect
- func (hub *Hub) GetLocalUserList(ctx context.Context, session *session.Session) *UserList
- func (hub *Hub) GetOnline(ctx context.Context, session *session.Session, online int) *OnLineList
- func (hub *Hub) GetServerHost() string
- func (hub *Hub) GetServerList() []builder.Address
- func (hub *Hub) GetServerPort() int
- func (hub *Hub) GetUser(key string, session *session.Session) *UserClient
- func (hub *Hub) Handler(ctx context.Context, version, remoteIP string, w http.ResponseWriter, ...) (*Connect, error)
- func (hub *Hub) HeartbeatSynDuration() int64
- func (hub *Hub) InConnect(conn *Connect) (ok bool)
- func (hub *Hub) IsLocalAddress(server string) bool
- func (hub *Hub) OnClosed(ctx context.Context, conn *Connect)
- func (hub *Hub) OnClosing(ctx context.Context, conn *Connect)
- func (hub *Hub) OnDestroy(ctx context.Context, conn *Connect)
- func (hub *Hub) OnHeartbeat(ctx context.Context, conn *Connect, timeAt int64)
- func (hub *Hub) OnLogin(ctx context.Context, user *session.Session, conn *Connect, timeAt int64)
- func (hub *Hub) OnLogout(ctx context.Context, user *session.Session, conn *Connect, timeAt int64)
- func (hub *Hub) OnReady(ctx context.Context, conn *Connect)
- func (hub *Hub) Process() Process
- func (hub *Hub) RateLimit(ctx context.Context, session *session.Session, version string) error
- func (hub *Hub) Receive(ctx context.Context, from *session.Session, to *session.Session, ev *Event) (err error)
- func (hub *Hub) ReceiveAll(ctx context.Context, from *session.Session, to *session.Session, ev *Event) (err error)
- func (hub *Hub) SendChat(ctx context.Context, from *session.Session, ev *Event, option chat.Option, ...) error
- func (hub *Hub) SendToAllUser(ctx context.Context, from *session.Session, to *session.Session, ev *Event)
- func (hub *Hub) SendToLocalAppId(ctx context.Context, from *session.Session, to *session.Session, ev *Event, ...)
- func (hub *Hub) SendToLocalUser(ctx context.Context, from *session.Session, to *session.Session, ev *Event) (error, bool)
- func (hub *Hub) SendToRemote(ctx context.Context, from *session.Session, to *session.Session, ev *Event)
- func (hub *Hub) SendToRemoteAppId(ctx context.Context, addr string, from *session.Session, to *session.Session, ...)
- func (hub *Hub) SendToRemoteUser(ctx context.Context, from *session.Session, to *session.Session, ev *Event) error
- func (hub *Hub) SendToUser(ctx context.Context, from *session.Session, to *session.Session, ev *Event) error
- func (hub *Hub) Source() string
- func (hub *Hub) Start(addr server.Address)
- func (hub *Hub) StatusChanged(ctx context.Context, us Status)
- func (hub *Hub) Stop()
- func (hub *Hub) SyncToRemoteOnly(ctx context.Context, from *session.Session, to *session.Session, ev *Event)
- func (hub *Hub) UseClientQuery(keys ...string) []*UserClient
- func (hub *Hub) UseSafe() bool
- type MemberFunc
- type Message
- type MessageMQ
- type Mq
- type MsgInterceptor
- type MsgInterceptorFunc
- type OnLineList
- type Online
- func (u *Online) Heartbeat(currentTime int64)
- func (u *Online) IsLocal(localIp string, localPort int) bool
- func (u *Online) IsOnline(heartCheck func(heartbeat int64) bool) bool
- func (u *Online) LogIn(currentTime int64)
- func (u *Online) LogOut(currentTime int64)
- func (u *Online) String() string
- func (u *Online) ToSession() session.Session
- type Option
- func WithAlarmOption(a Alarm) Option
- func WithChatGroupOption(group chat.Group) Option
- func WithChatOption(chat chat.Chat) Option
- func WithDiscoveryClientOption(client discoveryservice.Client) Option
- func WithMsgInterceptorOption(a MsgInterceptor) Option
- func WithProcessOption(p Process) Option
- func WithRpcClientOption(rpc rpc.Client) Option
- func WithTargetOption(t builder.Target) Option
- func WithUpgraderCheckOriginOption(checkOrigin func(r *http.Request) bool) Option
- func WithUpgraderEnableCompressionOption(enable bool) Option
- func WithUpgraderErrOption(err func(w http.ResponseWriter, r *http.Request, status int, reason error)) Option
- func WithUpgraderHandshakeTimeoutOption(d time.Duration) Option
- func WithUpgraderReadBufferSizeOption(size int) Option
- func WithUpgraderSubprotocolsOption(subprotocols []string) Option
- func WithUpgraderWriteBufferSizeOption(size int) Option
- func WithUseMQOption() Option
- func WithUserMgrOption(user User) Option
- func WithWorkerNumOption(work int) Option
- type OptionConnect
- type OptionDial
- func WithWsEnableCompressionOption(enable bool) OptionDial
- func WithWsHandshakeTimeout(t time.Duration) OptionDial
- func WithWsJarOption(jar http.CookieJar) OptionDial
- func WithWsProxyOption(proxy func(*http.Request) (*url.URL, error)) OptionDial
- func WithWsReadBufferSizeOption(size int) OptionDial
- func WithWsSubprotocolsOption(subprotocols []string) OptionDial
- func WithWsTlsOption(config *tls.Config) OptionDial
- func WithWsWriteBufferSizeOption(size int) OptionDial
- type Process
- type Query
- type QueryFunc
- type ReqHead
- func (h *ReqHead) GetRecvAt() int64
- func (h *ReqHead) GetReqAt() int64
- func (h *ReqHead) GetSeqId() string
- func (h *ReqHead) GetSource() string
- func (h *ReqHead) GetTimeOut() time.Duration
- func (h *ReqHead) GetVersion() string
- func (h *ReqHead) SetSource(source string)
- func (h *ReqHead) SetTimeOut(duration time.Duration)
- type ResCmd
- type ResHead
- type RespInterceptor
- type RespInterceptorFunc
- type Status
- type UnaryDisposeInterceptor
- type User
- type UserClient
- func (c *UserClient) Close(ctx context.Context, reason string) error
- func (c *UserClient) EqualConnect(conn *Connect) bool
- func (c *UserClient) GetAddr() string
- func (c *UserClient) GetConnect() *Connect
- func (c *UserClient) GetConnectId() uint64
- func (c *UserClient) GetConnectTime() int64
- func (c *UserClient) GetHeartTime() int64
- func (c *UserClient) GetIndex() int64
- func (c *UserClient) GetRemoteIP() string
- func (c *UserClient) GetSession() session.Session
- func (c *UserClient) GetSource() string
- func (c *UserClient) GetSyncTime() int64
- func (c *UserClient) IsClosed() bool
- func (c *UserClient) IsLogin() bool
- func (c *UserClient) Login(ctx context.Context) error
- func (c *UserClient) Logout(ctx context.Context) error
- func (c *UserClient) Send(ctx context.Context, eventType EventType, body []byte) error
- func (c *UserClient) SendMQ(ctx context.Context, topic string, content string) error
- func (c *UserClient) SendTo(msg []byte) error
- func (c *UserClient) SendToQueue(ctx context.Context, msg []byte) error
- func (c *UserClient) String() string
- func (c *UserClient) Subscribe(ctx context.Context, topic ...string) error
- func (c *UserClient) UnSubscribe(ctx context.Context, topic ...string) error
- type UserList
Constants ¶
const ( CmdCreate = 1 CmdDestroy = 2 CmdClose = 3 CmdNotSession = 4 )
const ( ETException = EventType(1) ETClientPing = EventType(2) ETClientPingRsp = EventType(3) // ETClientBegin 客户端开始 ETClientBegin = EventType(10) ETClientHeartBeat = EventType(10) ETClientHeartBeatRsp = EventType(11) // ETClientLogin 登录 ETClientLogin = EventType(100) ETClientLoginRsp = EventType(101) ETClientLogout = EventType(102) ETClientLogoutRsp = EventType(103) // ETClientUserStatusChanged 用户状态发生变化 ETClientUserStatusChanged = EventType(104) ETClientUserStatusChangedRsp = EventType(105) ETClientUserList = EventType(106) ETClientUserListRsp = EventType(107) // ETClientKicked 多端使用,被踢 ETClientKicked = EventType(108) ETClientKickedRsp = EventType(109) // ETMessage 消息事件 ETMessage = EventType(200) ETMessageRsp = EventType(201) ETNotify = EventType(202) ETNotifyRsp = EventType(203) // ETChat 聊天事件 ETChat = EventType(204) ETChatRsp = EventType(205) // ETMq 简单的mq ETMq = EventType(206) ETMqRsp = EventType(207) // ETBody 简单的消息 ETBody = EventType(208) ETBodyRsp = EventType(209) // ETClientEnd 客户端结束 ETClientEnd = EventType(4999) // ETServerBegin 服务之间 ETServerBegin = EventType(5000) ETServerEnd = EventType(10000) // ETExServerBegin 外部服务 ETExServerBegin = EventType(20000) ETExServerEnd = EventType(30000) )
const ( MQMsg = iota + 1 EVMsg )
const ( SubscribeMQ = iota UnSubscribeMQ SendMQ )
const ( SMsgLog = 1 << iota //发送 RMsgLog //接受 HeartMsgLog AMsgLog = 255 //全部 )
const ( StatusOffline = 1 StatusOnline = 2 StatusHeartbeat = 3 )
const HeartbeatDurationOpt = 10001
const (
IgnoreStatusBroadcast = 1
)
const (
LoginAction = Action("login")
)
Variables ¶
var (
EmptyByte = []byte("")
)
var GrcClientNil = result.Error(-102, "not exist rpc client")
var Ignored = result.Error(-103, "ignore the error")
var MQNotSupport = result.Error(-104, "not support MQ")
var NotExistRemoteServer = result.Error(-100, "not exist remote server")
var NotMemberErr = errors.New("is not member")
var StatusDesc = map[int32]string{ StatusOffline: "离开", StatusOnline: "在线", }
var UserObjNil = result.Error(-101, "not exist remote user")
Functions ¶
func AddResEventType ¶ added in v0.4.6
func AddResEventType(ev EventType)
AddResEventType not safe operation, best in process init
func BuildConn ¶ added in v0.5.6
func BuildConn(url string, head http.Header, resp func(resp *http.Response), opts ...OptionDial) (*websocket.Conn, error)
BuildConn for ws connect
func BytesToString ¶ added in v0.5.5
BytesToString []byte 转 string (零分配)
func DefaultRespInterceptor ¶ added in v0.4.28
func IsClientEvent ¶
func IsEventType ¶ added in v0.4.6
func IsExServerEvent ¶
func IsServerEvent ¶
func IsUserStatusChanged ¶
func NewContext ¶ added in v0.1.18
func NewWithTraceId ¶ added in v0.1.9
func RemoveResEventType ¶ added in v0.4.6
func RemoveResEventType(ev EventType)
RemoveResEventType not safe operation, best in process init
func SdkVersion ¶ added in v0.2.9
func SdkVersion() string
func StringEvent ¶ added in v0.1.9
func StringToBytes ¶ added in v0.5.5
StringToBytes string 转 []byte (零分配)
Types ¶
type Client ¶
type Client interface {
GetSource() string
GetIndex() int64
GetHeartTime() int64
GetSyncTime() int64
GetConnectId() uint64
GetAddr() string
GetRemoteIP() string
GetConnectTime() int64
IsClosed() bool
Close(ctx context.Context, reason string) error
SendTo(msg []byte) error
SendToQueue(ctx context.Context, msg []byte) error
}
type Config ¶
type Config struct {
WorkForceReset bool `json:"workForceReset" yaml:"workForceReset"`
RegisterClient int `json:"registerClient" yaml:"registerClient"` // 是否同步添加client
HeartbeatDuration int64 `json:"heartbeatDuration" yaml:"heartbeatDuration"` //秒,client连接心跳检查间隔时长
HeartbeatInterval int64 `json:"heartbeatInterval" yaml:"heartbeatInterval"` //秒,心跳同步时长
UserStatusChange bool `json:"userStatusChange" yaml:"userStatusChange"` //用户状态,是否需要通知
Safe bool `json:"safe" yaml:"safe"` //是否安全方式,string to []byte OR []byte to string
}
type Connect ¶
type Connect struct {
// contains filtered or unexported fields
}
func NewConnect ¶ added in v0.4.0
func (*Connect) AddSession ¶ added in v0.4.0
func (*Connect) GetConnectId ¶ added in v0.4.0
func (*Connect) GetConnectTime ¶ added in v0.4.0
func (*Connect) GetHeartTime ¶ added in v0.4.0
func (*Connect) GetRemoteIP ¶ added in v0.4.0
func (*Connect) GetSessionKey ¶ added in v0.4.0
func (*Connect) GetSyncTime ¶ added in v0.4.0
func (*Connect) HasSession ¶ added in v0.4.5
func (*Connect) RemoveSession ¶ added in v0.4.0
func (*Connect) SendMQ ¶ added in v0.4.20
func (c *Connect) SendMQ(ctx context.Context, session *session.Session, topic string, content string) error
SendMQ send mq pack
func (*Connect) SendToQueue ¶ added in v0.4.0
type ConnectCmd ¶ added in v0.4.0
type DisposeInterceptor ¶ added in v0.4.7
func ChainDispose ¶ added in v0.4.6
func ChainDispose(fn DisposeInterceptor) DisposeInterceptor
type Event ¶
type Event struct {
TraceId string `json:"-"`
EvTypeBase int32 `json:"-"` // 事件基数
EventType int32 `json:"eventType"` // 事件类型, EventType
ContentType string `json:"contentType"` // Content 格式,json,xml...protobuff, 默认json
Content string `json:"content"` // 具体的业务数据
}
func CreateObjEvent ¶ added in v0.2.20
type EventReq ¶
type EventRes ¶
func NewResponse ¶
type FromMemberFunc ¶ added in v0.4.0
FromMemberFunc 是否是群成员, is= true 是成员
type Handler ¶ added in v0.5.4
type Handler interface {
// HeartbeatSynDuration 心跳同步时长(单位秒)
HeartbeatSynDuration() int64
Source() string
Process() Process
// OnReady 链接准备好了
OnReady(ctx context.Context, conn *Connect)
// OnClosing close之前
OnClosing(ctx context.Context, conn *Connect)
OnClosed(ctx context.Context, conn *Connect)
OnDestroy(ctx context.Context, conn *Connect)
// OnHeartbeat websocket发生心跳的回调
OnHeartbeat(ctx context.Context, conn *Connect, timeAt int64)
// OnLogin 用户
OnLogin(ctx context.Context, user *session.Session, conn *Connect, timeAt int64)
OnLogout(ctx context.Context, user *session.Session, conn *Connect, timeAt int64)
}
type Hub ¶ added in v0.2.11
type Hub struct {
// contains filtered or unexported fields
}
func (*Hub) AddConnect ¶ added in v0.4.0
func (*Hub) AddUser ¶ added in v0.4.22
func (hub *Hub) AddUser(userKey string, client *UserClient)
func (*Hub) CheckAllUserOnline ¶ added in v0.2.11
func (*Hub) CheckUserOnline ¶ added in v0.2.11
CheckUserOnline 查询用户是否在线
func (*Hub) ConnectQuery ¶ added in v0.4.0
func (*Hub) ConnectSearch ¶ added in v0.4.0
func (*Hub) DelConnect ¶ added in v0.4.0
func (*Hub) GetAllUserList ¶ added in v0.2.11
GetAllUserList 查询所有用户
func (*Hub) GetAppList ¶ added in v0.3.5
func (*Hub) GetConnects ¶ added in v0.4.0
func (*Hub) GetLocalUserList ¶ added in v0.2.11
GetLocalUserList 本机的用户
func (*Hub) GetServerHost ¶ added in v0.2.11
func (*Hub) GetServerList ¶ added in v0.5.11
func (*Hub) GetServerPort ¶ added in v0.2.11
func (*Hub) GetUser ¶ added in v0.4.0
func (hub *Hub) GetUser(key string, session *session.Session) *UserClient
func (*Hub) HeartbeatSynDuration ¶ added in v0.4.0
func (*Hub) IsLocalAddress ¶ added in v0.2.11
func (*Hub) OnHeartbeat ¶ added in v0.4.0
func (*Hub) ReceiveAll ¶ added in v0.2.11
func (*Hub) SendToAllUser ¶ added in v0.2.11
func (hub *Hub) SendToAllUser(ctx context.Context, from *session.Session, to *session.Session, ev *Event)
SendToAllUser 给全体用户发消息
func (*Hub) SendToLocalAppId ¶ added in v0.2.11
func (hub *Hub) SendToLocalAppId(ctx context.Context, from *session.Session, to *session.Session, ev *Event, payload any)
SendToLocalAppId 给本地 指定的客户端appid 送消息到, 除了userId payload 用户定义的数据结构(内部使用)
func (*Hub) SendToLocalUser ¶ added in v0.2.11
func (hub *Hub) SendToLocalUser(ctx context.Context, from *session.Session, to *session.Session, ev *Event) (error, bool)
SendToLocalUser 给本机指定用户发送消息
func (*Hub) SendToRemote ¶ added in v0.2.11
func (hub *Hub) SendToRemote(ctx context.Context, from *session.Session, to *session.Session, ev *Event)
SendToRemote 发送到远端
func (*Hub) SendToRemoteAppId ¶ added in v0.2.11
func (*Hub) SendToRemoteUser ¶ added in v0.2.11
func (*Hub) SendToUser ¶ added in v0.2.11
func (hub *Hub) SendToUser(ctx context.Context, from *session.Session, to *session.Session, ev *Event) error
SendToUser 给指定在线用户发送消息
func (*Hub) StatusChanged ¶ added in v0.2.11
func (*Hub) SyncToRemoteOnly ¶ added in v0.2.11
func (hub *Hub) SyncToRemoteOnly(ctx context.Context, from *session.Session, to *session.Session, ev *Event)
SyncToRemoteOnly 仅仅只同步到远端
func (*Hub) UseClientQuery ¶ added in v0.4.0
func (hub *Hub) UseClientQuery(keys ...string) []*UserClient
type Message ¶ added in v0.5.5
type Mq ¶ added in v0.2.11
type Mq struct {
// contains filtered or unexported fields
}
type MsgInterceptor ¶ added in v0.4.0
type MsgInterceptorFunc ¶ added in v0.4.0
type OnLineList ¶ added in v0.2.21
type Online ¶
type Online struct {
ID string `json:"id"`
AppId string `json:"appId"`
ClientIp string `json:"clientIp"` // 客户端Ip
ClientPort string `json:"clientPort"` // 客户端端口
RemoteIp string `json:"remoteIp"` // 用户远程IP
Host string `json:"host"` // 用户所在的服务器ip
Version string `json:"version"` // 版本信息
Name string `json:"name"` // 名称
Account string `json:"account"`
UserId int64 `json:"userId"`
Port int `json:"port"` // 用户所在的服务器端口
Plat int32 `json:"plat"`
LoginTime int64 `json:"loginTime"` // 用户上次登录时间
HeartbeatTime int64 `json:"heartbeatTime"` // 用户上次心跳时间
LogOutTime int64 `json:"logOutTime"` // 用户退出登录的时间
IsOffline bool `json:"isOffline"` // 是否离线
}
type Option ¶
type Option func(hub *Hub)
func WithAlarmOption ¶ added in v0.4.0
func WithChatGroupOption ¶ added in v0.2.11
WithChatGroupOption 群管理及群聊
func WithChatOption ¶ added in v0.2.15
WithChatOption 聊天信息保存
func WithDiscoveryClientOption ¶ added in v0.2.15
func WithDiscoveryClientOption(client discoveryservice.Client) Option
WithDiscoveryClientOption 分布式支持
func WithMsgInterceptorOption ¶ added in v0.4.0
func WithMsgInterceptorOption(a MsgInterceptor) Option
func WithProcessOption ¶ added in v0.5.1
WithProcessOption 处理器
func WithRpcClientOption ¶ added in v0.2.11
WithRpcClientOption 外部服务接用
func WithTargetOption ¶ added in v0.5.11
func WithUpgraderCheckOriginOption ¶ added in v0.4.0
func WithUpgraderEnableCompressionOption ¶ added in v0.4.0
func WithUpgraderErrOption ¶ added in v0.4.0
func WithUpgraderHandshakeTimeoutOption ¶ added in v0.4.0
func WithUpgraderReadBufferSizeOption ¶ added in v0.4.0
func WithUpgraderSubprotocolsOption ¶ added in v0.4.0
func WithUpgraderWriteBufferSizeOption ¶ added in v0.4.0
func WithUserMgrOption ¶ added in v0.2.11
WithUserMgrOption 用户管理
func WithWorkerNumOption ¶ added in v0.2.13
WithWorkerNumOption 配置工作线程
type OptionConnect ¶ added in v0.4.1
type OptionConnect func(conn *Connect)
func WithConnHeartbeatDuration ¶ added in v0.4.1
func WithConnHeartbeatDuration(t int64) OptionConnect
type OptionDial ¶ added in v0.4.7
func WithWsEnableCompressionOption ¶ added in v0.4.7
func WithWsEnableCompressionOption(enable bool) OptionDial
func WithWsHandshakeTimeout ¶ added in v0.4.7
func WithWsHandshakeTimeout(t time.Duration) OptionDial
func WithWsJarOption ¶ added in v0.4.7
func WithWsJarOption(jar http.CookieJar) OptionDial
func WithWsProxyOption ¶ added in v0.4.7
func WithWsReadBufferSizeOption ¶ added in v0.4.7
func WithWsReadBufferSizeOption(size int) OptionDial
func WithWsSubprotocolsOption ¶ added in v0.4.7
func WithWsSubprotocolsOption(subprotocols []string) OptionDial
func WithWsTlsOption ¶ added in v0.4.7
func WithWsTlsOption(config *tls.Config) OptionDial
func WithWsWriteBufferSizeOption ¶ added in v0.4.7
func WithWsWriteBufferSizeOption(size int) OptionDial
type Process ¶ added in v0.5.1
type Process interface {
SetMessageLog(log int)
GetMessageLog() int
HasMessageLog(log int) bool
PrintLog(evType int32) bool
SetRespInterceptor(fn RespInterceptorFunc)
GetRespInterceptor() RespInterceptorFunc
SetUnaryDisposeInterceptor(fn UnaryDisposeInterceptor)
GetUnaryDisposeInterceptor() UnaryDisposeInterceptor
RegisterDispose(key int32, fn DisposeInterceptor)
GetDispose(key int32) (DisposeInterceptor, bool)
}
func NewProcess ¶ added in v0.5.1
func NewProcess() Process
type ReqHead ¶
type ReqHead struct {
Source string `json:"source"`
Version string `json:"version"`
SeqId string `json:"seqId"`
ReqAt int64 `json:"timeAt"` //客户端或服务器的时间
RecvAt int64 `json:"-"` //服务器收到的时间
TimeOut time.Duration `json:"-"`
}
func (*ReqHead) GetTimeOut ¶
GetTimeOut request.HeadV2 interface
func (*ReqHead) GetVersion ¶
GetVersion request.Head interface
func (*ReqHead) SetTimeOut ¶
SetTimeOut request.HeadV2 interface
type ResHead ¶
type ResHead struct {
result.Result
Version string `json:"version"` //版本,请求者版本
Source string `json:"source,omitempty"` //请求源,可以请求者填写
SeqId string `json:"seqId,omitempty"` //请求序号,由请求者定义,服务器原路返回
TimeAt int64 `json:"timeAt,omitempty"` //服务收到请求的时间(ms)
DiffAt int64 `json:"diffAt,omitempty"` //客户端与服务端时间差值(ms)
SpendAt int64 `json:"spendAt,omitempty"` //从服务收到请求到响应完成,所花的时长(ms)
ServerAt int64 `json:"serverAt,omitempty"` //服务器时间,豪秒,用于检验对时(ms)
LogId string `json:"logId,omitempty"`
}
type RespInterceptor ¶ added in v0.4.6
RespInterceptor 回复拦截器
type RespInterceptorFunc ¶ added in v0.4.6
func ChainRespInterceptor ¶ added in v0.4.28
func ChainRespInterceptor(fn RespInterceptorFunc) RespInterceptorFunc
func (RespInterceptorFunc) RespInterceptor ¶ added in v0.4.6
func (f RespInterceptorFunc) RespInterceptor(req *EventReq) bool
type Status ¶
type UnaryDisposeInterceptor ¶ added in v0.4.7
type UnaryDisposeInterceptor func(conn *Connect, req *EventReq, handler DisposeInterceptor) (resp any, err error)
type User ¶
type User interface {
// HeartbeatTimeout (秒)用户在线心跳超时时长
HeartbeatTimeout() int64
SetSupportApp(apps []session.Terminal)
NextSupportApp(ctx context.Context, fn func(app session.Terminal) bool)
ExistSupportApp(ctx context.Context, app session.Terminal) bool
// RateLimit 是否限速
RateLimit(ctx context.Context, session *session.Session, version string) error
GetUserKey(session *session.Session) string
// AllowUser 是否允许
AllowUser(ctx context.Context, session *session.Session, action Action) (Attribute, error)
// GetUserOnline 获取所有 online =1 在线;=2 离线 3=
GetUserOnline(ctx context.Context, session *session.Session, online int) (*Online, error)
// SetUserOnline 可以保存到redis
SetUserOnline(ctx context.Context, session *session.Session, online *Online) error
RemoveUserOnline(ctx context.Context, session *session.Session) error
IsUserOnline(ctx context.Context, session *session.Session) (bool, error)
// GetAllOnline 获取所有 online =1 在线;=2 离线 3=
GetAllOnline(ctx context.Context, cc *Copy, session *session.Session, online int) error
//UserStatusChanged 通知其它服务有变化
UserStatusChanged(ctx context.Context, status *Status)
}
type UserClient ¶ added in v0.4.0
func BuildClient ¶ added in v0.1.22
func (*UserClient) Close ¶ added in v0.4.2
func (c *UserClient) Close(ctx context.Context, reason string) error
func (*UserClient) EqualConnect ¶ added in v0.4.0
func (c *UserClient) EqualConnect(conn *Connect) bool
func (*UserClient) GetAddr ¶ added in v0.4.0
func (c *UserClient) GetAddr() string
func (*UserClient) GetConnect ¶ added in v0.4.2
func (c *UserClient) GetConnect() *Connect
func (*UserClient) GetConnectId ¶ added in v0.4.0
func (c *UserClient) GetConnectId() uint64
func (*UserClient) GetConnectTime ¶ added in v0.4.0
func (c *UserClient) GetConnectTime() int64
func (*UserClient) GetHeartTime ¶ added in v0.4.0
func (c *UserClient) GetHeartTime() int64
func (*UserClient) GetIndex ¶ added in v0.4.0
func (c *UserClient) GetIndex() int64
func (*UserClient) GetRemoteIP ¶ added in v0.4.0
func (c *UserClient) GetRemoteIP() string
func (*UserClient) GetSession ¶ added in v0.4.0
func (c *UserClient) GetSession() session.Session
func (*UserClient) GetSource ¶ added in v0.4.0
func (c *UserClient) GetSource() string
func (*UserClient) GetSyncTime ¶ added in v0.4.0
func (c *UserClient) GetSyncTime() int64
func (*UserClient) IsClosed ¶ added in v0.4.0
func (c *UserClient) IsClosed() bool
func (*UserClient) IsLogin ¶ added in v0.4.0
func (c *UserClient) IsLogin() bool
func (*UserClient) Login ¶ added in v0.4.0
func (c *UserClient) Login(ctx context.Context) error
Login send login pack
func (*UserClient) Logout ¶ added in v0.4.0
func (c *UserClient) Logout(ctx context.Context) error
Logout send logout pack
func (*UserClient) SendTo ¶ added in v0.4.0
func (c *UserClient) SendTo(msg []byte) error
func (*UserClient) SendToQueue ¶ added in v0.4.0
func (c *UserClient) SendToQueue(ctx context.Context, msg []byte) error
func (*UserClient) String ¶ added in v0.4.0
func (c *UserClient) String() string
func (*UserClient) Subscribe ¶ added in v0.4.0
func (c *UserClient) Subscribe(ctx context.Context, topic ...string) error
Subscribe send subscribe pack
func (*UserClient) UnSubscribe ¶ added in v0.4.0
func (c *UserClient) UnSubscribe(ctx context.Context, topic ...string) error
UnSubscribe send unsubscribe pack
