Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
8cc1c024
提交
8cc1c024
authored
5月 23, 2025
作者:
mooncake9527
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rl可直接传入redis conn,省去一个redis conn
上级
867bafca
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
7 行删除
+7
-7
sync_ratelimiter.go
gin/middleware/sync_ratelimiter/sync_ratelimiter.go
+3
-3
glog.go
sgorm/glog/glog.go
+4
-4
没有找到文件。
gin/middleware/sync_ratelimiter/sync_ratelimiter.go
浏览文件 @
8cc1c024
...
@@ -24,14 +24,14 @@ func (d *RedisDatastore) fullKey(key string, start int64) string {
...
@@ -24,14 +24,14 @@ func (d *RedisDatastore) fullKey(key string, start int64) string {
func
(
d
*
RedisDatastore
)
Add
(
ctx
context
.
Context
,
key
string
,
start
,
value
int64
)
(
int64
,
error
)
{
func
(
d
*
RedisDatastore
)
Add
(
ctx
context
.
Context
,
key
string
,
start
,
value
int64
)
(
int64
,
error
)
{
k
:=
d
.
fullKey
(
key
,
start
)
k
:=
d
.
fullKey
(
key
,
start
)
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
c
,
err
:=
d
.
client
.
IncrBy
(
c
ontext
.
Background
()
,
k
,
value
)
.
Result
()
c
,
err
:=
d
.
client
.
IncrBy
(
c
tx
,
k
,
value
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
if
d
.
logger
!=
nil
{
if
d
.
logger
!=
nil
{
d
.
logger
.
Error
(
fmt
.
Sprintf
(
"[SlideWindow] add fail,[k:%s add:%d]"
,
k
,
value
),
zap
.
String
(
"err"
,
err
.
Error
()),
zap
.
String
(
"cost"
,
time
.
Since
(
startTime
)
.
String
()),
xctx
.
CtxTraceIDField
(
ctx
))
d
.
logger
.
Error
(
fmt
.
Sprintf
(
"[SlideWindow] add fail,[k:%s add:%d]"
,
k
,
value
),
zap
.
String
(
"err"
,
err
.
Error
()),
zap
.
String
(
"cost"
,
time
.
Since
(
startTime
)
.
String
()),
xctx
.
CtxTraceIDField
(
ctx
))
}
}
return
0
,
err
return
0
,
err
}
}
_
,
_
=
d
.
client
.
Expire
(
c
ontext
.
Background
()
,
k
,
d
.
ttl
)
.
Result
()
_
,
_
=
d
.
client
.
Expire
(
c
tx
,
k
,
d
.
ttl
)
.
Result
()
if
d
.
logger
!=
nil
{
if
d
.
logger
!=
nil
{
d
.
logger
.
Info
(
fmt
.
Sprintf
(
"[SlideWindow] add success,[k:%s add:%d -> %d]"
,
k
,
value
,
c
),
zap
.
String
(
"cost"
,
time
.
Since
(
startTime
)
.
String
()),
xctx
.
CtxTraceIDField
(
ctx
))
d
.
logger
.
Info
(
fmt
.
Sprintf
(
"[SlideWindow] add success,[k:%s add:%d -> %d]"
,
k
,
value
,
c
),
zap
.
String
(
"cost"
,
time
.
Since
(
startTime
)
.
String
()),
xctx
.
CtxTraceIDField
(
ctx
))
}
}
...
@@ -41,7 +41,7 @@ func (d *RedisDatastore) Add(ctx context.Context, key string, start, value int64
...
@@ -41,7 +41,7 @@ func (d *RedisDatastore) Add(ctx context.Context, key string, start, value int64
func
(
d
*
RedisDatastore
)
Get
(
ctx
context
.
Context
,
key
string
,
start
int64
)
(
int64
,
error
)
{
func
(
d
*
RedisDatastore
)
Get
(
ctx
context
.
Context
,
key
string
,
start
int64
)
(
int64
,
error
)
{
k
:=
d
.
fullKey
(
key
,
start
)
k
:=
d
.
fullKey
(
key
,
start
)
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
value
,
err
:=
d
.
client
.
Get
(
c
ontext
.
Background
()
,
k
)
.
Result
()
value
,
err
:=
d
.
client
.
Get
(
c
tx
,
k
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
if
err
==
redis
.
Nil
{
if
err
==
redis
.
Nil
{
err
=
nil
err
=
nil
...
...
sgorm/glog/glog.go
浏览文件 @
8cc1c024
...
@@ -28,7 +28,7 @@ func NewCustomGormLogger(l *zap.Logger, requestIDKey string, logLevel logger.Log
...
@@ -28,7 +28,7 @@ func NewCustomGormLogger(l *zap.Logger, requestIDKey string, logLevel logger.Log
l
,
_
=
zap
.
NewProduction
()
l
,
_
=
zap
.
NewProduction
()
}
}
if
requestIDKey
==
""
{
if
requestIDKey
==
""
{
requestIDKey
=
"
request_id
"
requestIDKey
=
"
traceID
"
}
}
if
logLevel
==
0
{
if
logLevel
==
0
{
logLevel
=
logger
.
Info
logLevel
=
logger
.
Info
...
@@ -96,7 +96,7 @@ func (l *gormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql
...
@@ -96,7 +96,7 @@ func (l *gormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql
}
}
if
err
!=
nil
{
if
err
!=
nil
{
l
.
gLog
.
Warn
(
"
gorm
"
,
l
.
gLog
.
Warn
(
"
[gorm]
"
,
zap
.
Error
(
err
),
zap
.
Error
(
err
),
zap
.
String
(
"sql"
,
sql
),
zap
.
String
(
"sql"
,
sql
),
rowsField
,
rowsField
,
...
@@ -108,7 +108,7 @@ func (l *gormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql
...
@@ -108,7 +108,7 @@ func (l *gormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql
}
}
if
l
.
logLevel
>=
logger
.
Info
{
if
l
.
logLevel
>=
logger
.
Info
{
l
.
gLog
.
Info
(
"
gorm
"
,
l
.
gLog
.
Info
(
"
[gorm]
"
,
zap
.
String
(
"sql"
,
sql
),
zap
.
String
(
"sql"
,
sql
),
rowsField
,
rowsField
,
zap
.
String
(
"cost"
,
cost
),
zap
.
String
(
"cost"
,
cost
),
...
@@ -119,7 +119,7 @@ func (l *gormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql
...
@@ -119,7 +119,7 @@ func (l *gormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql
}
}
if
l
.
logLevel
>=
logger
.
Warn
{
if
l
.
logLevel
>=
logger
.
Warn
{
l
.
gLog
.
Warn
(
"
gorm
"
,
l
.
gLog
.
Warn
(
"
[gorm]
"
,
zap
.
String
(
"sql"
,
sql
),
zap
.
String
(
"sql"
,
sql
),
rowsField
,
rowsField
,
zap
.
String
(
"cost"
,
cost
),
zap
.
String
(
"cost"
,
cost
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论