Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CnChunfeng
/
go-websocket
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2d0f44e3
authored
Sep 21, 2022
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加消息记录
parent
09c3af54
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
7 deletions
internal/cmd/websocket/main.go
internal/logic/websocket_logic/common.go
logs/2022-09-21.log
internal/cmd/websocket/main.go
View file @
2d0f44e3
...
...
@@ -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
}
}
...
...
internal/logic/websocket_logic/common.go
View file @
2d0f44e3
...
...
@@ -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
()
{
...
...
logs/2022-09-21.log
0 → 100644
View file @
2d0f44e3
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"}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment