MCPcopy Create free account
hub / github.com/LockGit/gochat / Push

Function Push

api/handler/push.go:25–64  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

23}
24
25func Push(c *gin.Context) {
26 var formPush FormPush
27 if err := c.ShouldBindBodyWith(&formPush, binding.JSON); err != nil {
28 tools.FailWithMsg(c, err.Error())
29 return
30 }
31 authToken := formPush.AuthToken
32 msg := formPush.Msg
33 toUserId := formPush.ToUserId
34 toUserIdInt, _ := strconv.Atoi(toUserId)
35 getUserNameReq := &proto.GetUserInfoRequest{UserId: toUserIdInt}
36 code, toUserName := rpc.RpcLogicObj.GetUserNameByUserId(getUserNameReq)
37 if code == tools.CodeFail {
38 tools.FailWithMsg(c, "rpc fail get friend userName")
39 return
40 }
41 checkAuthReq := &proto.CheckAuthRequest{AuthToken: authToken}
42 code, fromUserId, fromUserName := rpc.RpcLogicObj.CheckAuth(checkAuthReq)
43 if code == tools.CodeFail {
44 tools.FailWithMsg(c, "rpc fail get self info")
45 return
46 }
47 roomId := formPush.RoomId
48 req := &proto.Send{
49 Msg: msg,
50 FromUserId: fromUserId,
51 FromUserName: fromUserName,
52 ToUserId: toUserIdInt,
53 ToUserName: toUserName,
54 RoomId: roomId,
55 Op: config.OpSingleSend,
56 }
57 code, rpcMsg := rpc.RpcLogicObj.Push(req)
58 if code == tools.CodeFail {
59 tools.FailWithMsg(c, rpcMsg)
60 return
61 }
62 tools.SuccessWithMsg(c, "ok", nil)
63 return
64}
65
66type FormRoom struct {
67 AuthToken string `form:"authToken" json:"authToken" binding:"required"`

Callers

nothing calls this directly

Calls 5

FailWithMsgFunction · 0.92
SuccessWithMsgFunction · 0.92
GetUserNameByUserIdMethod · 0.45
CheckAuthMethod · 0.45
PushMethod · 0.45

Tested by

no test coverage detected