model

package
v0.0.0-...-8be65b2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEntity

type BaseEntity struct {
	Id        string         `gorm:"primarykey;type:varchar(32);not null" json:"id"`
	CreatedAt time.Time      `json:"createAt"`
	UpdatedAt time.Time      `json:"updateAt"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"`
}

type CommunityEntity

type CommunityEntity struct {
	BaseEntity
	CommunityId string `gorm:"type:varchar(32);not null;INDEX" json:"communityId" binding:"required,min=6,max=12" label:"群id"`
	Name        string `gorm:"type:varchar(32);not null" json:"Name" binding:"required,min=1,max=12" label:"群名称"`
	OwnerId     string `gorm:"type:varchar(32);not null" json:"ownerId" binding:"required" label:"群主id"`
	Face        string `gorm:"type:varchar(100);not null" json:"face" label:"群头像"`
	Memo        string `gorm:"type:varchar(100);" json:"memo" label:"群描述"`
	Extend      string `gorm:"-" json:"extend"`
}

func (CommunityEntity) Delete

func (community CommunityEntity) Delete(cid string) int

Delete 删

func (CommunityEntity) Insert

func (community CommunityEntity) Insert() int

Insert 增

func (CommunityEntity) SelectBy

func (community CommunityEntity) SelectBy(query any) (CommunityEntity, int)

SelectBy 查单条

func (CommunityEntity) TableName

func (CommunityEntity) TableName() string

func (CommunityEntity) Update

func (community CommunityEntity) Update(cid string) int

Update 改

type Message

type Message struct {
	// 消息id
	Id string `json:"id"`
	// 发送者id
	SenderId string `json:"senderId"`
	// 接受者id
	ReceiverId string `json:"receiverId"`
	// 消息内容
	Content string `json:"content"`
	// 附加信息
	Extra string `json:"extra"`
	// 消息类型 前端用来判断 后端不处理
	ContentType int `json:"contentType"`
	// 处理类型 见status
	ProcessType int `json:"processType"`
	// 发送时间
	SendTime string `json:"sendTime"`
	// 源数据
	Resource []byte `json:"resource"`
}

传输消息结构

func ToMessage

func ToMessage(data []byte) Message

ToMessage []byte转message

type Node

type Node struct {
	// websocket连接
	Conn *websocket.Conn
	// 数据存储队列
	DataQueue chan []byte
	// 群id的set
	GroupSets set.Interface
}

一个用户对应一个node

func NewNode

func NewNode(conn *websocket.Conn) *Node

NewNode 创建新的node

type NodeGroup

type NodeGroup struct {
	NodeMap map[string]*Node
	Locker  sync.RWMutex
}

全局node存储 {key:uid value:node}

func NewNodeGroup

func NewNodeGroup() *NodeGroup

NewNodeGroup 新建NodeGroup 全局维护一个

func (*NodeGroup) Add

func (ng *NodeGroup) Add(id string, conn *websocket.Conn) (node *Node, ok bool)

Add 添加node

func (*NodeGroup) Delete

func (ng *NodeGroup) Delete(id string)

Delete 删除node

func (*NodeGroup) SendGroupMessage

func (ng *NodeGroup) SendGroupMessage(msg Message)

SendGroupMessage 发送群消息

func (*NodeGroup) SendMessage

func (ng *NodeGroup) SendMessage(msg Message) (ok bool)

SendMessage 发送消息

type OfflineGroup

type OfflineGroup struct {
	OfflineMap map[string][]Message
	Locker     sync.RWMutex
}

离线消息存储

func NewOfflineGroup

func NewOfflineGroup() *OfflineGroup

NewOfflineGroup 新建OfflineGroup 全局维护一个

func (*OfflineGroup) Add

func (og *OfflineGroup) Add(msg Message)

Add 添加消息

func (*OfflineGroup) Delete

func (og *OfflineGroup) Delete(id string)

Delete 删除消息

type RelationEntity

type RelationEntity struct {
	BaseEntity
	UserId        string          `gorm:"type:varchar(32);not null" json:"userId" binding:"required,min=6,max=15" label:"用户id"`
	FriendId      string          `gorm:"type:varchar(32);not null" json:"friendId" binding:"required,min=6,max=15" label:"好友id"`
	RelationType  int             `gorm:"type:int;DEFAULT:1" json:"relationType" binding:"required" label:"关系类型"`
	RoleType      int             `gorm:"type:int;DEFAULT:1" json:"roleType" binding:"required" label:"角色类型"`
	Memo          string          `gorm:"type:varchar(120);DEFAULT:NULL" json:"memo" label:"描述"`
	Extend        string          `gorm:"-" json:"extend"`
	FriendInfo    UserEntity      `gorm:"foreignKey:UserId;references:UserId;" json:"friendInfo"`
	ProposerInfo  UserEntity      `gorm:"foreignKey:UserId;references:FriendId;" json:"proposerInfo"`
	CommunityInfo CommunityEntity `gorm:"foreignKey:CommunityId;references:FriendId;" json:"communityInfo"`
}

func (RelationEntity) AddFriend

func (relation RelationEntity) AddFriend() int

AddFriend 添加好友

func (RelationEntity) Delete

func (relation RelationEntity) Delete(id string) int

Delete 删

func (RelationEntity) Insert

func (relation RelationEntity) Insert() int

Insert 增

func (RelationEntity) RemoveFriend

func (relation RelationEntity) RemoveFriend() int

RemoveFriend 删除好友

func (RelationEntity) SelectBy

func (relation RelationEntity) SelectBy(query any, role int) (RelationEntity, int)

SelectBy 查单条

func (RelationEntity) SelectListBy

func (relation RelationEntity) SelectListBy(query any, role int) ([]RelationEntity, int)

SelectListBy 查多条

func (RelationEntity) TableName

func (RelationEntity) TableName() string

func (RelationEntity) Update

func (relation RelationEntity) Update(query any, args ...any) int

Update 改

type UserEntity

type UserEntity struct {
	BaseEntity
	NickName  string `gorm:"type:varchar(32);not null;INDEX" json:"nickName" binding:"required,min=1,max=12" label:"昵称"`
	UserId    string `gorm:"type:varchar(32);not null " json:"userId" binding:"required,min=6,max=15" label:"用户id"`
	Password  string `gorm:"type:varchar(100);not null " json:"password" binding:"required,min=6,max=15" label:"密码"`
	UserRole  int    `gorm:"type:int;DEFAULT:1" json:"userRole" binding:"required" label:"角色类型"`
	Gender    int    `gorm:"type:int;DEFAULT:1" json:"gender" label:"性别"`
	Signature string `gorm:"type:varchar(255) " json:"signature" label:"个人签名"`
	Mobile    string `gorm:"type:varchar(16) " json:"mobile" label:"电话"`
	Face      string `gorm:"type:varchar(255) " json:"face" label:"头像"`
}

func (UserEntity) Delete

func (user UserEntity) Delete(uid string) int

Delete 删

func (UserEntity) Insert

func (user UserEntity) Insert() int

Insert 增

func (UserEntity) SelectBy

func (user UserEntity) SelectBy(query any) (UserEntity, int)

SelectBy 查单条

func (UserEntity) TableName

func (UserEntity) TableName() string

func (UserEntity) Update

func (user UserEntity) Update(uid string) int

Update 改

Jump to

Keyboard shortcuts

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