Documentation ¶
Overview ¶
@Title ws 相关数据模型
Index ¶
- Constants
- func CreateGameUser(user *GameUser) (int64, error)
- func GetDbInst() *gorm.DB
- func GetRedisInst() *redis.Pool
- func InitModel()
- func UpdateGameUser(user *GameUser) error
- type EventModel
- type EventType
- type GameErrorContent
- type GamePixelRecord
- type GameUser
- type Subscriber
- type UserWsConnectionCounter
Constants ¶
View Source
const ( EventHeartbeat EventMessage EventBroadcast )
Variables ¶
This section is empty.
Functions ¶
func CreateGameUser ¶
func UpdateGameUser ¶
Types ¶
type EventModel ¶
type EventModel struct { Type EventType // JOIN, LEAVE, MESSAGE Sub *Subscriber // 广播请传 nil Timestamp int64 // Unix timestamp (secs) Content interface{} }
ws 消息
type GameErrorContent ¶
type GameErrorContent struct { Id int64 `gorm:"primary_key" json:"id"` Message string `json:"message"` Source string `json:"source"` Lineno string `json:"lineno"` Colno string `json:"colno"` Stack string `json:"stack"` Uid int64 `json:"uid"` CreatedAt string `json:"created_at"` }
GameErrorContent 错误记录
type GamePixelRecord ¶
type GamePixelRecord struct { Id int64 `gorm:"primary_key" json:"id"` X int64 `json:"x"` Y int64 `json:"y"` Color int64 `json:"color"` Uid int64 `json:"uid"` CreatedAt string `json:"created_at"` }
GamePixelRecord 像素操作记录
type GameUser ¶
type GameUser struct { Id int64 `gorm:"primary_key" json:"id"` Nickname string `json:"nickname"` AccessToken string `json:"access_token"` Status int8 `json:"status"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` }
GameUser 游戏用户
func GetGameUserById ¶
func GetUserByAccessToken ¶
type Subscriber ¶
type Subscriber struct { Uuid string // 连接唯一ID Ping int64 // 最后心跳时间 Uid int64 // 用户ID Conn *websocket.Conn // ws 客户端连接句柄 Request *http.Request // http 请求 WriteChan chan *EventModel // 发消息通道 (这里用指针是为了防止 channel 拷贝数据,造成资源浪费,特别是广播时候) WriteChanLock sync.Mutex StopChan chan bool // 用于监控连接中断信号 Limiter *rate.Limiter // 令牌桶 限制速率 }
Subscriber 代表一个客户端连接
func (*Subscriber) WriteMsg ¶
func (sub *Subscriber) WriteMsg(event *EventModel)
default 模型用,写入消息到写通道
type UserWsConnectionCounter ¶
type UserWsConnectionCounter struct {
// contains filtered or unexported fields
}
UserWsConnectionCounter 用于记录 WebSocket 连接数
func NewUserWsConnectionCounter ¶
func NewUserWsConnectionCounter() *UserWsConnectionCounter
NewUserWsConnectionCounter 创建一个新的 UserWsConnectionCounter 实例
func (*UserWsConnectionCounter) AddConnection ¶
func (c *UserWsConnectionCounter) AddConnection(uid int64)
AddConnection 为指定的 UID 增加一个连接
func (*UserWsConnectionCounter) GetConnectionCount ¶
func (c *UserWsConnectionCounter) GetConnectionCount(uid int64) int64
GetConnectionCount 获取指定 UID 的连接数
func (*UserWsConnectionCounter) RemoveConnection ¶
func (c *UserWsConnectionCounter) RemoveConnection(uid int64)
RemoveConnection 为指定的 UID 移除一个连接
Click to show internal directories.
Click to hide internal directories.