Change logging to be json comaptible
This commit is contained in:
@@ -114,6 +114,9 @@ func RateLimitByIPDynamic(maxFn func() int, per time.Duration, burstFn func() in
|
||||
}
|
||||
|
||||
return func(c *gin.Context) {
|
||||
log := StructuredLog(c).With().
|
||||
Str("event", "rate_limit_check").
|
||||
Logger()
|
||||
|
||||
// Kinda a shitty fix
|
||||
if c.FullPath() == "/api/files/upload/chunk" || c.FullPath() == "/api/files/upload/init" || c.FullPath() == "/api/files/upload/complete" {
|
||||
@@ -136,6 +139,12 @@ func RateLimitByIPDynamic(maxFn func() int, per time.Duration, burstFn func() in
|
||||
client := getClient(ip, now, max, burst)
|
||||
|
||||
if !client.bucket.allow() {
|
||||
log.Warn().
|
||||
Str("ip", ip).
|
||||
Int("max", max).
|
||||
Int("burst", burst).
|
||||
Msg("Rate limit exceeded")
|
||||
|
||||
c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{
|
||||
"error": "rate limit exceeded",
|
||||
})
|
||||
@@ -144,4 +153,4 @@ func RateLimitByIPDynamic(maxFn func() int, per time.Duration, burstFn func() in
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user