server

package
v0.0.0-...-686d10b Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TomatoInfo = map[string]string{}

TomatoInfo ...

Functions

func GetRelatedRoles

func GetRelatedRoles(roleID string) []string

func GetUserRoles

func GetUserRoles(userID string) []string

GetUserRoles 获取用户对应的角色列表

func PushError

func PushError(ws *WebSocket, code int, errMsg string, reconnect bool)

PushError 发送错误信息

func RunWebSocketServer

func RunWebSocketServer(pattern, addr string, h WebSocketHandler)

RunWebSocketServer ...

func Validate

func Validate(data t.M, op string) error

Validate 校验客户端发送的请求是否合法

Types

type Client

type Client struct {
	SubscriptionInfos map[int]*SubscriptionInfo
	PushConnect       func(int, t.M, t.M)
	PushSubscribe     func(int, t.M, t.M)
	PushUnsubscribe   func(int, t.M, t.M)
	PushCreate        func(int, t.M, t.M)
	PushEnter         func(int, t.M, t.M)
	PushUpdate        func(int, t.M, t.M)
	PushDelete        func(int, t.M, t.M)
	PushLeave         func(int, t.M, t.M)
	// contains filtered or unexported fields
}

Client 客户端信息 ws 当前对象的 WebSocket 连接 SubscriptionInfos 当前客户端发起的所有请求对应的订阅信息

func NewClient

func NewClient(id int, ws *WebSocket) *Client

NewClient ...

func (*Client) AddSubscriptionInfo

func (c *Client) AddSubscriptionInfo(requestID int, subscriptionInfo *SubscriptionInfo)

AddSubscriptionInfo 添加 requestID 对应的订阅信息

func (*Client) DeleteSubscriptionInfo

func (c *Client) DeleteSubscriptionInfo(requestID int)

DeleteSubscriptionInfo 删除 requestID 对应的订阅信息

func (*Client) GetSubscriptionInfo

func (c *Client) GetSubscriptionInfo(requestID int) *SubscriptionInfo

GetSubscriptionInfo 获取 requestID 对应的订阅信息

type SessionTokenCache

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

SessionTokenCache 缓存 SessionToken 及其对应的用户 ID

func NewSessionTokenCache

func NewSessionTokenCache() *SessionTokenCache

NewSessionTokenCache ...

func (*SessionTokenCache) GetUserID

func (s *SessionTokenCache) GetUserID(sessionToken string) string

GetUserID 获取用户 ID

type Subscription

type Subscription struct {
	Query            t.M
	ClassName        string
	Hash             string
	ClientRequestIDs map[int][]int
}

Subscription 订阅对象 一组 ClassName Hash 对应唯一一个对象 ClientRequestIDs 记录连接到该对象的所有客户端

func NewSubscription

func NewSubscription(className string, query t.M, queryHash string) *Subscription

NewSubscription ...

func (*Subscription) AddClientSubscription

func (s *Subscription) AddClientSubscription(clientID, requestID int)

AddClientSubscription 添加连接到该订阅对象的客户端请求

func (*Subscription) DeleteClientSubscription

func (s *Subscription) DeleteClientSubscription(clientID, requestID int)

DeleteClientSubscription 删除连接到该订阅对象的客户端请求

func (*Subscription) HasSubscribingClient

func (s *Subscription) HasSubscribingClient() bool

HasSubscribingClient 返回连接到该对象的客户端数量

type SubscriptionInfo

type SubscriptionInfo struct {
	Subscription *Subscription
	SessionToken string
	Fields       []string
}

SubscriptionInfo 订阅对象信息 每一个客户端请求对应一个对象

type WebSocket

type WebSocket struct {
	ClientID int
	// contains filtered or unexported fields
}

WebSocket ...

type WebSocketHandler

type WebSocketHandler interface {
	OnConnect(ws *WebSocket)
	OnMessage(ws *WebSocket, msg interface{})
	OnDisconnect(ws *WebSocket)
}

WebSocketHandler ...

Jump to

Keyboard shortcuts

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