Commit 2d0f44e3 by Joneq

增加消息记录

parent 09c3af54
......@@ -12,10 +12,6 @@ import (
func main() {
websocket_logic.WriteLog()
panic(1)
s := g.Server()
s.BindHandler("/ws", func(r *ghttp.Request) {
var ctx = r.Context()
......@@ -26,10 +22,14 @@ func main() {
}
for {
msgType, msg, err := ws.ReadMessage()
websocket_logic.WriteLog(string(msg))
if err != nil {
return
}
if err = ws.WriteMessage(msgType, msg); err != nil {
if err = ws.WriteMessage(msgType, []byte("消息接收成功")); err != nil {
return
}
}
......
......@@ -6,10 +6,27 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
//发送消息结构题
type MsgStruct struct {
SendUserName string `json:"send_user_name"`
SendUserId int `json:"send_user_id"`
GetUserName string `json:"get_user_name"`
GetUserId int `json:"get_user_id"`
SendDate string `json:"send_date"`
ExtInfo string `json:"ext_info"`
MsgType string `json:"msg_type"`
}
//公公层
func WriteLog() {
WriteJsonLog()
func WriteLog(msg string) {
ctx := context.TODO()
type User struct {
Uid int `json:"uid"`
Name string `json:"name"`
}
g.Log().Debug(ctx, User{100, msg})
}
func WriteJsonLog() {
......
2022-09-21 16:58:52.256 [DEBU] {"uid":100,"name":"发送消息成功"}
2022-09-21 17:00:14.033 [DEBU] {"uid":100,"name":"发送消息成功"}
2022-09-21 17:24:24.128 [DEBU] {"uid":100,"name":"消息发送成功"}
2022-09-21 17:26:22.839 [DEBU] {"uid":100,"name":"息接收成功"}
2022-09-21 17:26:26.636 [DEBU] {"uid":100,"name":""}
2022-09-21 17:26:36.892 [DEBU] {"uid":100,"name":"发送消息成功"}
2022-09-21 17:26:37.963 [DEBU] {"uid":100,"name":""}
2022-09-21 17:26:40.910 [DEBU] {"uid":100,"name":""}
2022-09-21 17:26:49.097 [DEBU] {"uid":100,"name":"发送消息成功"}
2022-09-21 17:27:21.182 [DEBU] {"uid":100,"name":"发送消息成功"}
2022-09-21 17:27:25.469 [DEBU] {"uid":100,"name":"发送消息成功"}
2022-09-21 17:27:35.683 [DEBU] {"uid":100,"name":"发送消息成功23232"}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment