Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a4d1ed6d
authored
Mar 18, 2026
by
gz1007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 支持通过环境变量配置搜索接口限流参数
parent
8ed2ea6e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
1 deletions
+9
-1
common/constants.go
+1
-0
common/init.go
+4
-0
middleware/rate-limit.go
+4
-1
No files found.
common/constants.go
View file @
a4d1ed6d
...
...
@@ -177,6 +177,7 @@ var (
DownloadRateLimitDuration
int64
=
60
// Per-user search rate limit (applies after authentication, keyed by user ID)
SearchRateLimitEnable
=
true
SearchRateLimitNum
=
10
SearchRateLimitDuration
int64
=
60
)
...
...
common/init.go
View file @
a4d1ed6d
...
...
@@ -120,6 +120,10 @@ func InitEnv() {
CriticalRateLimitEnable
=
GetEnvOrDefaultBool
(
"CRITICAL_RATE_LIMIT_ENABLE"
,
true
)
CriticalRateLimitNum
=
GetEnvOrDefault
(
"CRITICAL_RATE_LIMIT"
,
20
)
CriticalRateLimitDuration
=
int64
(
GetEnvOrDefault
(
"CRITICAL_RATE_LIMIT_DURATION"
,
20
*
60
))
SearchRateLimitEnable
=
GetEnvOrDefaultBool
(
"SEARCH_RATE_LIMIT_ENABLE"
,
true
)
SearchRateLimitNum
=
GetEnvOrDefault
(
"SEARCH_RATE_LIMIT"
,
10
)
SearchRateLimitDuration
=
int64
(
GetEnvOrDefault
(
"SEARCH_RATE_LIMIT_DURATION"
,
60
))
initConstantEnv
()
}
...
...
middleware/rate-limit.go
View file @
a4d1ed6d
...
...
@@ -196,7 +196,10 @@ func userRedisRateLimiter(c *gin.Context, maxRequestNum int, duration int64, key
}
// SearchRateLimit returns a per-user rate limiter for search endpoints.
//
10 requests per 60 seconds per user (by user ID, not IP)
.
//
Configurable via SEARCH_RATE_LIMIT_ENABLE / SEARCH_RATE_LIMIT / SEARCH_RATE_LIMIT_DURATION
.
func
SearchRateLimit
()
func
(
c
*
gin
.
Context
)
{
if
!
common
.
SearchRateLimitEnable
{
return
defNext
}
return
userRateLimitFactory
(
common
.
SearchRateLimitNum
,
common
.
SearchRateLimitDuration
,
"SR"
)
}
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