Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
ba03c808
提交
ba03c808
authored
8月 22, 2025
作者:
mooncake9527
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
ce21a10a
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
64 行增加
和
11 行删除
+64
-11
memory.go
cache/memory.go
+0
-1
ctx.go
gin/ctxUtils/ctx.go
+5
-1
response.go
gin/response/response.go
+18
-2
query_condition.go
sgorm/query/query_condition.go
+2
-0
xsf.go
utils/xsf/xsf.go
+8
-0
ws.go
ws/ws.go
+31
-7
没有找到文件。
cache/memory.go
浏览文件 @
ba03c808
...
...
@@ -197,7 +197,6 @@ func (m *memoryCache) MGet(ctx context.Context, keys []string) ([]any, error) {
}
logger
.
Info
(
fmt
.
Sprintf
(
"%s mget"
,
logPrefix
),
logger
.
Any
(
"key"
,
xslice
.
Join
(
keys
,
" "
)),
logger
.
Any
(
"val"
,
rs
),
logger
.
Any
(
"cost"
,
time
.
Since
(
st
)
.
String
()),
logger
.
Any
(
"expiration"
,
DefaultNotFoundExpireTime
.
String
()),
ctxUtil
.
CtxTraceIDField
(
ctx
))
...
...
gin/ctxUtils/ctx.go
浏览文件 @
ba03c808
...
...
@@ -112,10 +112,14 @@ func CtxTraceIDField(c context.Context) zap.Field {
return
zap
.
String
(
ContextTraceIDKey
,
CtxRequestID
(
c
))
}
func
NewCtx
()
context
.
Context
{
func
New
Empty
Ctx
()
context
.
Context
{
return
context
.
WithValue
(
context
.
Background
(),
ContextTraceIDKey
,
GenerateTid
())
}
func
NewCtx
(
ctx
context
.
Context
)
context
.
Context
{
return
context
.
WithValue
(
context
.
Background
(),
ContextTraceIDKey
,
ctx
.
Value
(
ContextTraceIDKey
))
}
func
GetGinUserID
(
c
*
gin
.
Context
)
xsf
.
ID
{
return
getGinVal
[
xsf
.
ID
](
c
,
KeyUID
)
}
...
...
gin/response/response.go
浏览文件 @
ba03c808
...
...
@@ -4,11 +4,13 @@ package response
import
(
"bytes"
"encoding/json"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli/entity"
"net/http"
"strconv"
"time"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/query"
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/errcode"
...
...
@@ -164,11 +166,25 @@ func Success(c *gin.Context, data ...interface{}) {
// SuccessWithPage return success
func
SuccessWithPage
[
T
any
](
c
*
gin
.
Context
,
list
[]
*
T
,
total
int64
)
{
currPage
:=
1
pageSize
:=
10
if
req
,
ok
:=
c
.
Get
(
"reqbody"
);
ok
{
if
pagination
,
ok
:=
req
.
(
query
.
IPagination
);
ok
{
currPage
=
pagination
.
GetPageIndex
()
pageSize
=
pagination
.
GetPageSize
()
}
}
totalPage
:=
total
/
int64
(
pageSize
)
if
total
%
int64
(
pageSize
)
>
0
{
totalPage
=
totalPage
+
1
}
c
.
Set
(
ctxUtils
.
KeyRspCode
,
1
)
if
list
==
nil
{
list
=
[]
*
T
{}
}
respJSONWith200
(
c
,
errcode
.
Success
.
Code
(),
errcode
.
Success
.
Msg
(),
gin
.
H
{
"list"
:
list
,
"total"
:
total
})
respJSONWith200
(
c
,
errcode
.
Success
.
Code
(),
errcode
.
Success
.
Msg
(),
gin
.
H
{
"list"
:
list
,
"totalCount"
:
total
,
"currPage"
:
currPage
,
"pageSize"
:
pageSize
,
"totalPage"
:
totalPage
,
})
}
// SuccessWithList return success
...
...
sgorm/query/query_condition.go
浏览文件 @
ba03c808
...
...
@@ -66,6 +66,8 @@ var logicMap = map[string]string{
type
IPagination
interface
{
GetOffset
()
int
GetLimit
()
int
GetPageIndex
()
int
GetPageSize
()
int
}
type
Pagination
struct
{
...
...
utils/xsf/xsf.go
浏览文件 @
ba03c808
...
...
@@ -26,7 +26,15 @@ func (f ID) MarshalJSON() ([]byte, error) {
return
buff
,
nil
}
func
(
f
*
ID
)
UnmarshalParam
(
src
string
)
error
{
return
f
.
unmarshal
([]
byte
(
src
))
}
func
(
f
*
ID
)
UnmarshalJSON
(
b
[]
byte
)
error
{
return
f
.
unmarshal
(
b
)
}
func
(
f
*
ID
)
unmarshal
(
b
[]
byte
)
error
{
if
len
(
b
)
==
0
{
return
nil
}
...
...
ws/ws.go
浏览文件 @
ba03c808
...
...
@@ -44,8 +44,12 @@ type WsConnManager struct {
}
type
Hook
interface
{
OnHeartbeatOK
(
receiverID
xsf
.
ID
)
error
OnHeartbeatFail
(
receiverID
xsf
.
ID
)
error
AfterSend
(
receiverID
xsf
.
ID
,
payload
*
WsMessage
)
error
AfterAccept
(
userID
xsf
.
ID
)
error
OnConnNotFound
(
receiverID
xsf
.
ID
,
payload
*
WsMessage
)
error
OnSendFail
(
receiverID
xsf
.
ID
,
payload
*
WsMessage
,
err
error
)
error
OnConnAccept
(
userID
xsf
.
ID
)
error
AfterUnregister
(
userID
xsf
.
ID
)
error
OnReceive
(
senderID
xsf
.
ID
,
messageType
int
,
msg
[]
byte
)
}
...
...
@@ -120,7 +124,7 @@ func (m *WsConnManager) accept(c *gin.Context) error {
m
.
register
(
client
)
for
_
,
h
:=
range
m
.
hooks
{
h
.
After
Accept
(
userID
)
h
.
OnConn
Accept
(
userID
)
}
return
nil
}
...
...
@@ -135,11 +139,20 @@ func (m *WsConnManager) getConn(userID xsf.ID) (*wsConn, bool) {
func
(
m
*
WsConnManager
)
Send
(
ctx
context
.
Context
,
receiverID
xsf
.
ID
,
payload
*
WsMessage
)
error
{
conn
,
exists
:=
m
.
getConn
(
receiverID
)
if
exists
{
err
:=
conn
.
send
(
ctx
,
payload
)
if
err
!=
nil
{
if
err
:=
conn
.
send
(
ctx
,
payload
);
err
!=
nil
{
for
_
,
h
:=
range
m
.
hooks
{
go
func
()
{
h
.
OnSendFail
(
receiverID
,
payload
,
err
)
}()
}
return
err
}
}
else
{
for
_
,
h
:=
range
m
.
hooks
{
go
func
()
{
h
.
OnConnNotFound
(
receiverID
,
payload
)
}()
}
return
xerror
.
Newf
(
"user[id:%d] ws conn not found"
,
receiverID
)
}
for
_
,
h
:=
range
m
.
hooks
{
...
...
@@ -177,10 +190,20 @@ func (c *wsConn) heartBeat() {
select
{
case
<-
ticker
.
C
:
if
err
:=
c
.
conn
.
WriteMessage
(
websocket
.
PingMessage
,
nil
);
err
!=
nil
{
for
_
,
h
:=
range
c
.
manager
.
hooks
{
go
func
()
{
h
.
OnHeartbeatFail
(
c
.
receiverID
)
}()
}
c
.
log
.
Error
(
"[ws][hearbeat]ping failed"
,
logger
.
Err
(
err
))
c
.
stop
<-
struct
{}{}
return
}
for
_
,
h
:=
range
c
.
manager
.
hooks
{
go
func
()
{
h
.
OnHeartbeatOK
(
c
.
receiverID
)
}()
}
case
<-
c
.
stop
:
c
.
log
.
Info
(
"[ws][hearbeat]stop signal received"
)
return
...
...
@@ -265,7 +288,8 @@ const (
)
type
WsMessage
struct
{
Seq
string
`json:"seq"`
Cmd
Cmd
`json:"cmd"`
Data
json
.
RawMessage
`json:"payload"`
// 原始JSON,目前是models.ChatMessage
Seq
string
`json:"seq"`
Cmd
Cmd
`json:"cmd"`
ReceiverID
xsf
.
ID
`json:"receiverID"`
Data
json
.
RawMessage
`json:"payload"`
// 原始JSON,目前是models.ChatMessage
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论