Documentation
¶
Index ¶
- Constants
- Variables
- func AddFriendInviteHandler(ctx *gin.Context)
- func AddGroupMemberHandler(ctx *gin.Context)
- func AuthLoginHandler(ctx *gin.Context)
- func AuthLogoutHandler(c *gin.Context)
- func AuthRegisterHandler(ctx *gin.Context)
- func CORSMiddleware() gin.HandlerFunc
- func CheckAuthMiddleware() gin.HandlerFunc
- func CreateGroupHandler(ctx *gin.Context)
- func DeleteChatMessageHandler(ctx *gin.Context)
- func FindFriendHandler(ctx *gin.Context)
- func GetProfileInfoHandler(c *gin.Context)
- func HTML(c *gin.Context, name string, obj ...any)
- func Init() *gin.Engine
- func JSON(c *gin.Context, obj ...any)
- func JSONError(c *gin.Context, errorCode int, errorMsg string, obj ...any)
- func JSONP(c *gin.Context, obj ...any)
- func JSONPError(c *gin.Context, errorCode int, errorMsg string, obj ...any)
- func JoinGroupHandler(ctx *gin.Context)
- func LeaveGroupHandler(ctx *gin.Context)
- func LoginUserFromContext(ctx *gin.Context) *database.User
- func MessageInvalidFormat(val string) string
- func RecoverMiddleware() gin.HandlerFunc
- func RemoveGroupMemberHandler(ctx *gin.Context)
- func RequestLogMiddleware() gin.HandlerFunc
- func RollbackChatMessageHandler(ctx *gin.Context)
- func SendChatMessageHandler(ctx *gin.Context)
- func SubscribeChatMessageHandler(ctx context.Context, payload *pubsub.Payload)
- func SubscribeFriendInviteHandler(ctx context.Context, payload *pubsub.Payload)
- func UpdateFriendHandle(ctx *gin.Context)
- func UpdateFriendInviteHandler(ctx *gin.Context)
- func UpdateGroupHandler(ctx *gin.Context)
- func UpdateGroupMemberHandler(ctx *gin.Context)
- func WebsocketHandler(ctx *gin.Context)
- func WebsocketMiddleware() gin.HandlerFunc
- type AddFriendInviteRequest
- type AddGroupMemberRequest
- type AddGroupMemberResponse
- type AuthLoginRequest
- type AuthLoginResponse
- type AuthRegisterRequest
- type AuthRegisterResponse
- type ChatMessageBody
- type CreateGroupRequest
- type CreateGroupResponse
- type FindFriendRequest
- type FindFriendResponse
- type JoinGroupRequest
- type LeaveGroupRequest
- type ProfileInfoResponse
- type RemoveGroupMemberRequest
- type RemoveGroupMemberResponse
- type Response
- type SendChatMessageRequest
- type SendChatMessageResponse
- type UpdateFriendInviteRequest
- type UpdateFriendRequest
- type UpdateGroupMemberRequest
- type UpdateGroupRequest
- type User
- type UserClaims
- type WebsocketMessageRequest
- type WebsocketMessageResponse
Constants ¶
const ( LOGIN_USER_CONTEXT_KEY = "LOGIN_USER" LOGIN_USER_ID_CONTEXT_KEY = "LOGIN_USER_ID" REQUEST_LOGGER_CONTEXT_KEY = "REQUEST_LOGGER" REQUEST_ID_CONTEXT_KEY = "REQUEST_ID" )
const ( StatusOK = 1 StatusError = 2 )
Variables ¶
var ( MessageInternalServerError = "内部服务错误" MessageInvalidParams = "参数无效" MessageInvalidGroupID = "'group_id'无效" MessageInvalidUserID = "'user_id'无效" MessageInvalidUserIDs = "'user_ids'无效" MessageInvalidUsername = "'username'无效" MessageInvalidNickname = "'nickname'无效" MessageInvalidPassword = "'password'无效" MessageInvalidSessionType = "'session_type'无效" MessageInvalidReceiverID = "'receiver_id'无效" MessageInvalidType = "'type'无效" MessageChatYourself = "不可与自己聊天" MessageNotFriends = "您与对方不是好友关系" MessageAlreadyfriends = "你们已经是好友关系" MessageBlockYou = "对方已将您拉黑" MessageInvalidTimeFormat = "时间格式无效" MessageAccountExists = "账户已存在" MessageAccountNotExists = "账户不存在" MessageAccountDisable = "账户已停用" MessageAccountDeleted = "账户已删除" MessageTargetNotExists = "对方不存在" MessageTargetDisable = "对方已停用" MessageTargetDeleted = "对方已删除" MessageIncorrectUsernameOrPassword = "用户名或密码错误" MessageConfirmPasswordWrong = "确认密码错误" )
Functions ¶
func AddFriendInviteHandler ¶
AddFriendInviteHandler @Summary 邀请加为好友 @Tags 朋友 @Accept json @Produce json @Param jsonRaw body AddFriendInviteRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/friend/invite/add [post]
func AddGroupMemberHandler ¶
AddGroupMemberHandler @Summary 增加群成员 @Tags 群组 @Accept json @Produce json @Param jsonRaw body AddGroupMemberRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response{data=AddGroupMemberResponse} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/group/member/add [post]
func AuthLoginHandler ¶
AuthLoginHandler @Summary 登陆 @Tags 认证 @Accept json @Produce json @Param jsonRaw body AuthLoginRequest true "请求JSON数据体" @Success 200 {object} Response{data=AuthLoginResponse} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/auth/login [post]
func AuthRegisterHandler ¶
AuthRegisterHandler @Summary 注册 @Tags 认证 @Accept json @Produce json @Param jsonRaw body AuthRegisterRequest true "请求JSON数据体" @Success 200 {object} Response{data=AuthRegisterResponse} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/auth/register [post]
func CheckAuthMiddleware ¶
func CheckAuthMiddleware() gin.HandlerFunc
CheckAuthMiddleware 检验认证中间件 一般http请求使用的认证中间件,websocket使用 WebsocketMiddleware 方法进行独立鉴权及日志收集
func CreateGroupHandler ¶
CreateGroupHandler @Summary 创建群 @Tags 群组 @Accept json @Produce json @Param jsonRaw body CreateGroupRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response{data=CreateGroupResponse} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/group/create [post]
func DeleteChatMessageHandler ¶
DeleteChatMessageHandler 删除聊天消息处理方法
func FindFriendHandler ¶
FindFriendHandler @Summary 查找好友 @Tags 朋友 @Accept json @Produce json @Param jsonRaw body FindFriendRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response{data=FindFriendResponse} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/friend/find [post]
func GetProfileInfoHandler ¶
GetProfileInfoHandler 获取个人画像信息
func JSONPError ¶
JSONPError 返回JSONP格式的错误数据
func JoinGroupHandler ¶
JoinGroupHandler @Summary 加入群 @Tags 群组 @Accept json @Produce json @Param jsonRaw body JoinGroupRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/group/join [post]
func LeaveGroupHandler ¶
LeaveGroupHandler @Summary 离开群 @Tags 群组 @Accept json @Produce json @Param jsonRaw body LeaveGroupRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/group/leave [post]
func LoginUserFromContext ¶
LoginUserFromContext 从上下文中获取当前登录的的用户信息 如果通过 checkAuth 方法鉴权过的,下文的 *gin.Context 必能找到用户信息
func MessageInvalidFormat ¶
MessageInvalidFormat 格式化参数无效错误
func RemoveGroupMemberHandler ¶
RemoveGroupMemberHandler @Summary 移除群成员 @Tags 群组 @Accept json @Produce json @Param jsonRaw body RemoveGroupMemberRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response{data=RemoveGroupMemberResponse} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/group/member/remove [post]
func RequestLogMiddleware ¶
func RequestLogMiddleware() gin.HandlerFunc
RequestLogMiddleware 请求日志中间件
func RollbackChatMessageHandler ¶
RollbackChatMessageHandler 回滚聊天消息处理方法
func SendChatMessageHandler ¶
SendChatMessageHandler @Summary 发送聊天消息 @Tags 聊天 @Accept json @Produce json @Param jsonRaw body SendChatMessageRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response{data=SendChatMessageResponse} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/chat/message/send [post]
func SubscribeChatMessageHandler ¶
SubscribeChatMessageHandler 接收聊天消息
func SubscribeFriendInviteHandler ¶
SubscribeFriendInviteHandler 订阅好友邀请控制器
func UpdateFriendHandle ¶
UpdateFriendHandle @Summary 更新朋友信息 // 可进行删除好友,拉黑好友 @Tags 朋友 @Accept json @Produce json @Param jsonRaw body UpdateFriendInviteRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/friend/update [post]
func UpdateFriendInviteHandler ¶
UpdateFriendInviteHandler @Summary 处理好友邀请 @Tags 朋友 @Accept json @Produce json @Param jsonRaw body UpdateFriendInviteRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/friend/invite/update [post]
func UpdateGroupHandler ¶
UpdateGroupHandler @Summary 更新群信息 @Tags 群组 @Accept json @Produce json @Param jsonRaw body UpdateGroupRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response{} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/group/update [post]
func UpdateGroupMemberHandler ¶
UpdateGroupMemberHandler @Summary 更新群成员 @Tags 群组 @Accept json @Produce json @Param jsonRaw body UpdateGroupMemberRequest true "请求JSON数据体" @Security APIKeyHeader @Success 200 {object} Response{} @Failure 400 {object} Response @Failure 404 {object} Response @Failure 500 {object} Response @Router /v1/group/member/update [post]
func WebsocketHandler ¶
WebsocketHandler websocket连接处理方法 `/api/ws`
func WebsocketMiddleware ¶
func WebsocketMiddleware() gin.HandlerFunc
WebsocketMiddleware websocket用的中间件 因为websocket连接会导致协程阻塞,无法进行到下一步,导致日志也一并堵塞 需要在ctx.Next() 之前调用 日志的send或者msg
Types ¶
type AddFriendInviteRequest ¶
type AddFriendInviteRequest struct {
// UserID 目标用户ID
UserID int64 `json:"user_id" binding:"required" min:"1" example:"1"`
// Note 添加好友时,给对方看的备注
Note string `json:"note" example:"你好,我是Jerbe"`
}
AddFriendInviteRequest 邀请用户成为好友操作请求参数 @Description 邀请用户成为好友操作请求参数
type AddGroupMemberRequest ¶
type AddGroupMemberRequest struct {
// GroupID 群ID
GroupID int64 `json:"group_id" binding:"required" example:"1098"`
// UserIDs 被邀请加入的用户ID列表
UserIDs []int64 `json:"user_ids" binding:"required" example:"1,2,3,4"`
}
AddGroupMemberRequest 增加群成员请求参数 @Description 增加群成员请求参数
type AddGroupMemberResponse ¶
type AddGroupMemberResponse struct {
// Count 成功加入群的成员数量
Count int64 `json:"count" binding:"required" example:"22"`
}
AddGroupMemberResponse 增加群成员返回参数 @Description 增加群返回请求参数
type AuthLoginRequest ¶
type AuthLoginRequest struct {
// Username 账户名
Username string `json:"username" binding:"required" example:"admin"`
// Password 密码
Password string `json:"password" binding:"required" example:"password"`
}
AuthLoginRequest @Description 用户登陆请求参数
type AuthLoginResponse ¶
type AuthLoginResponse struct {
// Token 认证Token
Token string `` /* 163-byte string literal not displayed */
// ExpiresAt 到期时间
ExpiresAt int64 `json:"expires_at" binding:"required" example:"1725249106"`
}
AuthLoginResponse 用户登陆返回数据 @Description 用户登陆返回参数
type AuthRegisterRequest ¶
type AuthRegisterRequest struct {
// Username 账户名
Username string `json:"username" binding:"required" example:"admin"`
// Password 密码
Password string `json:"password" binding:"required" minLength:"8" example:"password"`
// ConfirmPassword 确认密码
ConfirmPassword string `json:"confirm_password" binding:"required" minLength:"8" example:"password"`
// BirthDate 生辰八字
BirthDate string `json:"birth_date,omitempty" minLength:"8" example:"2016-01-02"`
// Nickname 昵称
Nickname string `json:"nickname,omitempty" minLength:"2" example:"昵称"`
}
AuthRegisterRequest @Description 用户注册请求参数
type AuthRegisterResponse ¶
type AuthRegisterResponse struct {
// UserID 用户ID
UserID *int64 `json:"user_id" binding:"required" example:"10086"`
// Username 账户名
Username string `json:"username" binding:"required" example:"admin"`
// Nickname 昵称
Nickname string `json:"nickname" binding:"required" example:"the king"`
// BirthDate 生辰八字
BirthDate string `form:"birth_date" binding:"required" example:"2016-01-02"`
// Avatar 头像地址
Avatar string `json:"avatar" binding:"required" example:"https://www.baidu.com/logo.png"`
}
AuthRegisterResponse @Description 用户注册返回数据
type ChatMessageBody ¶
type ChatMessageBody struct {
// 文本信息。适用消息类型: 1
Text string `json:"text,omitempty" example:"这是一条聊天文案"`
// 来源地址。通用字段,适用消息类型: 2,3,4
Src string `json:"src,omitempty" example:"https://www.baidu.com/logo.png"`
// 文件格式。适用消息类型: 2,3,4
Format string `json:"format,omitempty" example:"jpeg"`
// 文件大小。适用消息类型: 2,3,4
Size string `json:"size,omitempty" example:"1234567890"`
// 位置信息-经度。 适用消息类型: 5
Longitude string `json:"longitude,omitempty" example:"0.213124212313"`
// 位置信息-纬度。 适用消息类型: 5
Latitude string `json:"latitude,omitempty" example:"0.913124212313"`
// 位置信息-地图缩放级别。 适用消息类型: 5
Scale float64 `json:"scale,omitempty" example:"0.22"`
// 位置信息标签。适用消息类型: 5
LocationLabel string `json:"location_label,omitempty" example:"成人影视学院"`
}
ChatMessageBody 消息主体 @Description 消息主体
type CreateGroupRequest ¶
type CreateGroupRequest struct {
// MemberIDs 其他成员的用户ID
MemberIDs []int64 `json:"member_ids" binding:"required" minLength:"1" maxLength:"50" example:"1,2,3,4"`
}
CreateGroupRequest 创建群请求参数 @Description 创建群请求参数
type CreateGroupResponse ¶
type CreateGroupResponse struct {
// GroupID 群ID
GroupID int64 `json:"group_id" binding:"required" example:"1098"`
// GroupName 群名称
GroupName string `json:"group_name" binding:"required" example:"群聊1098"`
}
CreateGroupResponse 创建群返回参数 @Description 创建群返回参数
type FindFriendRequest ¶
type FindFriendRequest struct {
// UserID 用户ID
UserID *int64 `json:"user_id" example:"1"`
// Nickname 昵称
Nickname *string `json:"nickname" example:"昵称"`
// StartID 开始搜索ID,下次搜索用上返回的最大ID
StartID *int64 `json:"start_id" example:"0"`
}
FindFriendRequest 查找好友请求参数 @Description 查找好友请求参数
type FindFriendResponse ¶
type FindFriendResponse struct {
Users []*User `json:"users" `
}
FindFriendResponse 查找好友返回参数 @Description 查找好友返回参数
type JoinGroupRequest ¶
type JoinGroupRequest struct {
// GroupID 群ID
GroupID int64 `json:"group_id" binding:"required" example:"1098"`
}
JoinGroupRequest 入群请求参数 @Description 入群请求参数
type LeaveGroupRequest ¶
type LeaveGroupRequest struct {
// GroupID 群ID
GroupID int64 `json:"group_id" binding:"required" example:"1098"`
}
LeaveGroupRequest 离群请求参数 @Description 离群请求参数
type ProfileInfoResponse ¶
type ProfileInfoResponse struct {
Username string `json:"username"`
BirthDate string `json:"birth_date" `
Avatar string `json:"avatar"`
OnlineStatus int `json:"online_status"`
}
==================================== ============ 账户信息 ================ ==================================== ProfileInfoResponse 个人画像的数据结构
type RemoveGroupMemberRequest ¶
type RemoveGroupMemberRequest struct {
// GroupID 群ID
GroupID int64 `json:"group_id" binding:"required" min:"1" example:"1"`
// UserIDs 当UserIDs为空时,表示主动当前用户退出群组,当不为空是表示将他人提出群组
UserIDs []int64 `json:"user_ids" binding:"required" example:"1,2,3,4"`
}
RemoveGroupMemberRequest 移除群成员请求参数 @Description 移除群成员请求参数
type RemoveGroupMemberResponse ¶
type RemoveGroupMemberResponse struct {
// Count 成功移除成员数量
Count int64 `json:"count" binding:"required" example:"22"`
}
RemoveGroupMemberResponse 移除群成员返回参数 @Description 移除群返回请求参数
type SendChatMessageRequest ¶
type SendChatMessageRequest struct {
// ActionID 行为ID,由前端生成
ActionID string `json:"action_id" example:"8d7a3bcd72"`
// ReceiverID 接收人; 可以是用户ID,也可以是群号
ReceiverID int64 `json:"receiver_id" binding:"required" example:"1234"`
// SessionType 会话类型; 1:私聊, 2:群聊
SessionType int `json:"session_type" binding:"required" enums:"1,2" example:"1"`
// Type 消息类型: 1-纯文本,2-图片,3-语音,4-视频, 5-位置
Type int `json:"type" enums:"1,2,3,4,5" binding:"required" example:"1"`
// Body 消息体;
Body ChatMessageBody `json:"body" binding:"required"`
}
SendChatMessageRequest 聊天发送消息请求参数 @Description 聊天发送消息请求参数
type SendChatMessageResponse ¶
type SendChatMessageResponse struct {
// 发送人ID
SenderID int64 `json:"sender_id" binding:"required" example:"1234456"`
// MessageID 消息ID
MessageID int64 `json:"message_id" binding:"required" example:"123"`
// CreatedAt 创建
CreatedAt int64 `json:"created_at" binding:"required" example:"12345678901234"`
SendChatMessageRequest
}
SendChatMessageResponse 发送聊天返回数据 @Description 发送聊天返回数据
type UpdateFriendInviteRequest ¶
type UpdateFriendInviteRequest struct {
// ID 邀请记录ID号
ID int64 `json:"id" binding:"required" min:"1" example:"1"`
// Status 设置状态
// 1-确认加为好友关系,2-拒绝加为好友
Status int `json:"status" binding:"required" enums:"1,2" example:"1"`
// Reply 回复信息
// status:1 为打招呼
// status:2 为拒绝理由
Reply string `json:"reply" example:"我拒绝"`
}
UpdateFriendInviteRequest 更新邀请好友请求 @Description 更新邀请好友请求
type UpdateFriendRequest ¶
type UpdateFriendRequest struct {
// UserID 对方的用户ID
UserID int64 `json:"user_id" binding:"required" min:"1" example:"1"`
// Status 好友状态, 0-删除对方
Status *int `json:"status" enums:"0" example:"0"`
// BlockStatus 黑名单状态, 0-把对方加入黑名单, 1-将对方从黑名单中移除
BlockStatus *int `json:"block_status" enums:"0" example:"1"`
// Remark 备注
Remark *string `json:"remark" example:"这个是我基友"`
}
UpdateFriendRequest 更新朋友信息请求参数 @Description 更新朋友信息请求参数
type UpdateGroupMemberRequest ¶
type UpdateGroupMemberRequest struct {
// GroupID 群ID
GroupID int64 `json:"group_id" binding:"required" example:"1098"`
// UserID 成员用户ID
UserID int64 `json:"user_id" binding:"required" example:"45"`
// Role 角色, 只能群主才可操作
Role *int `json:"role,omitempty" enums:"0,2" example:"0"`
// SpeakStatus 发言权限, 管理者以上都可以操作, 管理员不能禁言管理员及以上权限的成员
SpeakStatus *int `json:"speak_status" enums:"0,1" example:"1"`
}
UpdateGroupMemberRequest @Description 更新群成员信息请求参数
type UpdateGroupRequest ¶
type UpdateGroupRequest struct {
// GroupID 群组ID
GroupID int64 `json:"group_id" binding:"required" example:"1098"`
// Name 群名称
Name *string `json:"name,omitempty" minLength:"1" maxLength:"50" example:"昵称"`
// SpeakStatus 发言状态, 必须为管理员以上级别
SpeakStatus *int `json:"speak_status,omitempty" enums:"0,1" example:"1"`
// OwnerID 新群主
OwnerID *int64 `json:"owner_id,omitempty" example:"1"`
}
UpdateGroupRequest 更新群组信息请求 @Description 更新群组信息请求参数
type User ¶
type User struct {
// ID 用户ID
ID int64 `json:"id" example:"10096"`
// Username 用户名
Username string `json:"username,omitempty" example:"admin"`
// Nickname 用户昵称
Nickname string `json:"nickname" example:"昵称"`
// BirthDate 出生日期
BirthDate *time.Time `json:"birth_date,omitempty" example:"2018-01-02"`
// Avatar 头像地址
Avatar string `json:"avatar,omitempty" format:"url" example:"https://www.baidu.com/logo.png"`
// OnlineStatus 在线状态
OnlineStatus int `json:"online_status,omitempty" enums:"0,1" example:"1"`
}
User @Description 用户信息结构
type UserClaims ¶
type UserClaims struct {
UserID int64 `json:"user_id"`
jwt.RegisteredClaims
}
UserClaims 用户认证使用的一些解码资料
type WebsocketMessageRequest ¶
type WebsocketMessageRequest struct {
Action string `json:"action"`
ActionID string `json:"action_id"`
Data any `json:"data"`
}
WebsocketMessageRequest websocket请求参数
type WebsocketMessageResponse ¶
type WebsocketMessageResponse struct {
Action string `json:"action"`
ActionID string `json:"action_id"`
Data any `json:"data"`
}
WebsocketMessageResponse websocket返回数据