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
71c26a58
authored
Nov 06, 2025
by
Leon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add environment variable switch for critical rate limit
parent
942a4311
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
4 deletions
+11
-4
common/constants.go
+4
-3
common/init.go
+3
-0
middleware/rate-limit.go
+4
-1
No files found.
common/constants.go
View file @
71c26a58
...
@@ -159,14 +159,15 @@ var (
...
@@ -159,14 +159,15 @@ var (
GlobalWebRateLimitNum
int
GlobalWebRateLimitNum
int
GlobalWebRateLimitDuration
int64
GlobalWebRateLimitDuration
int64
CriticalRateLimitEnable
bool
CriticalRateLimitNum
=
20
CriticalRateLimitDuration
int64
=
20
*
60
UploadRateLimitNum
=
10
UploadRateLimitNum
=
10
UploadRateLimitDuration
int64
=
60
UploadRateLimitDuration
int64
=
60
DownloadRateLimitNum
=
10
DownloadRateLimitNum
=
10
DownloadRateLimitDuration
int64
=
60
DownloadRateLimitDuration
int64
=
60
CriticalRateLimitNum
=
20
CriticalRateLimitDuration
int64
=
20
*
60
)
)
var
RateLimitKeyExpirationDuration
=
20
*
time
.
Minute
var
RateLimitKeyExpirationDuration
=
20
*
time
.
Minute
...
...
common/init.go
View file @
71c26a58
...
@@ -99,6 +99,9 @@ func InitEnv() {
...
@@ -99,6 +99,9 @@ func InitEnv() {
GlobalWebRateLimitNum
=
GetEnvOrDefault
(
"GLOBAL_WEB_RATE_LIMIT"
,
60
)
GlobalWebRateLimitNum
=
GetEnvOrDefault
(
"GLOBAL_WEB_RATE_LIMIT"
,
60
)
GlobalWebRateLimitDuration
=
int64
(
GetEnvOrDefault
(
"GLOBAL_WEB_RATE_LIMIT_DURATION"
,
180
))
GlobalWebRateLimitDuration
=
int64
(
GetEnvOrDefault
(
"GLOBAL_WEB_RATE_LIMIT_DURATION"
,
180
))
CriticalRateLimitEnable
=
GetEnvOrDefaultBool
(
"CRITICAL_RATE_LIMIT_ENABLE"
,
true
)
CriticalRateLimitNum
=
GetEnvOrDefault
(
"CRITICAL_RATE_LIMIT"
,
20
)
CriticalRateLimitDuration
=
int64
(
GetEnvOrDefault
(
"CRITICAL_RATE_LIMIT_DURATION"
,
20
*
60
))
initConstantEnv
()
initConstantEnv
()
}
}
...
...
middleware/rate-limit.go
View file @
71c26a58
...
@@ -102,7 +102,10 @@ func GlobalAPIRateLimit() func(c *gin.Context) {
...
@@ -102,7 +102,10 @@ func GlobalAPIRateLimit() func(c *gin.Context) {
}
}
func
CriticalRateLimit
()
func
(
c
*
gin
.
Context
)
{
func
CriticalRateLimit
()
func
(
c
*
gin
.
Context
)
{
return
rateLimitFactory
(
common
.
CriticalRateLimitNum
,
common
.
CriticalRateLimitDuration
,
"CT"
)
if
common
.
CriticalRateLimitEnable
{
return
rateLimitFactory
(
common
.
CriticalRateLimitNum
,
common
.
CriticalRateLimitDuration
,
"CT"
)
}
return
defNext
}
}
func
DownloadRateLimit
()
func
(
c
*
gin
.
Context
)
{
func
DownloadRateLimit
()
func
(
c
*
gin
.
Context
)
{
...
...
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