-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP rate-limiting as middleware per user
- Loading branch information
1 parent
1ef35d4
commit 87147d8
Showing
2 changed files
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/NikitosnikN/go-claude-tg-bot/internal/domain/user" | ||
"gopkg.in/telebot.v3" | ||
) | ||
|
||
// RateLimit middleware for tg bot | ||
func RateLimit(requestsPerSecond int) telebot.MiddlewareFunc { | ||
return func(next telebot.HandlerFunc) telebot.HandlerFunc { | ||
return func(c telebot.Context) error { | ||
u := c.Get(string(user.UserInfoContextKey)).(*user.User) | ||
|
||
if u == nil { | ||
return next(c) | ||
} | ||
|
||
// TODO implement rate limiter | ||
|
||
return next(c) | ||
} | ||
} | ||
} |