models

package
v0.0.0-...-eb3c019 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

@Title ws 相关数据模型

Index

Constants

View Source
const (
	EventHeartbeat
	EventMessage
	EventBroadcast
)

Variables

This section is empty.

Functions

func CreateGameUser

func CreateGameUser(user *GameUser) (int64, error)

func GetDbInst

func GetDbInst() *gorm.DB

获取主库实例

func GetRedisInst

func GetRedisInst() *redis.Pool

获取redis

func InitModel

func InitModel()

func UpdateGameUser

func UpdateGameUser(user *GameUser) error

Types

type EventModel

type EventModel struct {
	Type      EventType   // JOIN, LEAVE, MESSAGE
	Sub       *Subscriber // 广播请传 nil
	Timestamp int64       // Unix timestamp (secs)
	Content   interface{}
}

ws 消息

type EventType

type EventType int

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 错误记录

func (*GameErrorContent) TableName

func (*GameErrorContent) TableName() string

自定义表名

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 像素操作记录

func (*GamePixelRecord) TableName

func (*GamePixelRecord) TableName() string

自定义表名

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 GetGameUserById(id int64) (*GameUser, error)

func GetUserByAccessToken

func GetUserByAccessToken(accessToken string) (*GameUser, error)

func (*GameUser) TableName

func (*GameUser) TableName() string

自定义表名

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 移除一个连接

Jump to

Keyboard shortcuts

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