Documentation ¶
Index ¶
- Constants
- Variables
- func AddToken(token string, email string)
- func CaptchaCheck(ctx *gin.Context, input string, email string) bool
- func CaptchaLogic(ctx *gin.Context, code, email string) error
- func ChgPwd(email string, oldPwd string, newPwd string) error
- func DeleteConn(userID int64)
- func DeleteToken(email string)
- func Email(ctx *gin.Context, email string) (code string, err error)
- func FindUserById(ctx *gin.Context, userid int64) (data map[string]interface{}, err error)
- func GetMyGroups(UserId int64) (*[]GetMyGroupResp, error)
- func GetToken(email string) string
- func GetUserFromAuth(ctx *gin.Context) (user *model.User, err error)
- func JudgeToken(token string, email string) bool
- func Login(email string, password string) (user *model.User, token string, err error)
- func ParseToken(tokenString string) (email string, id int64, tokenTime time.Time, err error)
- func Register(user *model.User, captcha string) (err error)
- func SendEmail(ctx context.Context, email string, captcha string) (err error)
- func SendToUser(userID int64, data interface{}, infoType PackageType) error
- func SetConn(userID int64, conn *Conn)
- func Sync(ctx *gin.Context, input *model.GroupMessageSyncInput) (*model.GroupMessageSyncOutput, error)
- func WSLoginAuth(tokenString string) (user *model.User, err error)
- type Conn
- type CreateGroupResp
- type GetMyGroupResp
- type GroupOperator
- func (gpo *GroupOperator) GetGroup(groupID int64) (*Group_, error)
- func (gpo *GroupOperator) GetMembersByGroupId(ctx *gin.Context, groupID int64) ([]map[string]interface{}, error)
- func (gpo *GroupOperator) JoinGroup(input *model.UserJoinGroupInput) error
- func (gpo *GroupOperator) QuitGroup()
- func (gpo *GroupOperator) SaveGroupMessage(SendInfo *model.GroupMessageInput) error
- func (gpo *GroupOperator) StoreGroup(groupID int64, group *Group_)
- func (gpo *GroupOperator) UpdateGroup()
- type Group_
- type Package
- type PackageType
Constants ¶
View Source
const (
CHAT_CODE_PREFIX = "CHAT_CODE_PREFIX"
)
View Source
const (
CHAT_TOKEN_PREFIX = "CHAT_TOKEN_PREFIX"
)
Variables ¶
View Source
var ConnsManager = sync.Map{} // (userID, conn)
View Source
var TokenMap sync.Map
Functions ¶
func DeleteToken ¶
func DeleteToken(email string)
func FindUserById ¶
func GetMyGroups ¶
func GetMyGroups(UserId int64) (*[]GetMyGroupResp, error)
func JudgeToken ¶
func ParseToken ¶
func SendToUser ¶
func SendToUser(userID int64, data interface{}, infoType PackageType) error
func Sync ¶
func Sync(ctx *gin.Context, input *model.GroupMessageSyncInput) (*model.GroupMessageSyncOutput, error)
Types ¶
type Conn ¶
type Conn struct { WSMutex sync.Mutex // WS写锁 WS *websocket.Conn // websocket连接 UserId int64 // 用户ID }
func (*Conn) Send ¶
func (c *Conn) Send(data interface{}, t PackageType) error
type CreateGroupResp ¶
type CreateGroupResp struct { GroupId int64 `json:"group_id"` OwnerId int64 `json:"owner_id"` Name string `json:"name"` Introduction string `json:"introduction"` UserNum int32 `json:"user_num"` CreateTime time.Time `json:"create_time"` MaxSeq int64 `json:"max_seq"` }
func CreateGroup ¶
func CreateGroup(Name string, Introduction string, OwnerId int64) (*CreateGroupResp, error)
type GetMyGroupResp ¶
type GroupOperator ¶
type GroupOperator struct { Groups []*Group_ GroupsMap sync.Map // contains filtered or unexported fields }
var GroupOp GroupOperator
func (*GroupOperator) GetGroup ¶
func (gpo *GroupOperator) GetGroup(groupID int64) (*Group_, error)
GetGroup 根据groupID获取群组, 能够保证获取的群组成员是最新的, 其他属性更新时需要保持DB中一致性
func (*GroupOperator) GetMembersByGroupId ¶
func (gpo *GroupOperator) GetMembersByGroupId(ctx *gin.Context, groupID int64) ([]map[string]interface{}, error)
GetMembersByGroupId GetUsersByGroupId 根据GroupID获取当前members
func (*GroupOperator) JoinGroup ¶
func (gpo *GroupOperator) JoinGroup(input *model.UserJoinGroupInput) error
JoinGroup 加入群组
func (*GroupOperator) SaveGroupMessage ¶
func (gpo *GroupOperator) SaveGroupMessage(SendInfo *model.GroupMessageInput) error
SaveGroupMessage 持久化群组消息, 同时会发送给每一个人
func (*GroupOperator) StoreGroup ¶
func (gpo *GroupOperator) StoreGroup(groupID int64, group *Group_)
type Group_ ¶
type Group_ struct { Members *[]model.GroupUser sync.RWMutex // contains filtered or unexported fields }
func (*Group_) SendGroupMessage ¶
func (g *Group_) SendGroupMessage(sendInfo *model.GroupMessageInput, seq int64)
SendGroupMessage 群发消息, 无锁
type Package ¶
type Package struct { //数据包内容, 按需修改 Type PackageType Data interface{} }
type PackageType ¶
type PackageType int
const ( PackageType_PT_ERR PackageType = 0 PackageType_PT_UNKNOWN PackageType = 0 PackageType_PT_SIGN_IN PackageType = 1 PackageType_PT_SYNC PackageType = 2 PackageType_PT_HEARTBEAT PackageType = 3 PackageType_PT_MESSAGE PackageType = 4 PackageType_PT_JOINGROUP PackageType = 5 )
Click to show internal directories.
Click to hide internal directories.