add developer documentation and custom rate limiter with banning
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 46s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 46s
Add a comprehensive guide for developers transitioning from Node/PHP and implement a new middleware to handle IP-based rate limiting with temporary banning functionality. Also refactors configuration loading to use a singleton pattern for better resource management.
This commit is contained in:
11
main.go
11
main.go
@@ -16,6 +16,8 @@ import (
|
||||
"emly-api-go/internal/database"
|
||||
"emly-api-go/internal/database/schema"
|
||||
"emly-api-go/internal/routes"
|
||||
|
||||
emlyMiddleware "emly-api-go/internal/middleware"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -52,6 +54,15 @@ func main() {
|
||||
// Global rate limit to 100 requests per minute
|
||||
r.Use(httprate.LimitByIP(100, time.Minute))
|
||||
|
||||
rl := emlyMiddleware.NewRateLimiter(
|
||||
5, // 5 req/sec per IP
|
||||
10, // burst fino a 10
|
||||
20, // ban dopo 20 violazioni
|
||||
30*time.Minute, // ban di 15 minuti
|
||||
)
|
||||
|
||||
r.Use(rl.Handler)
|
||||
|
||||
routes.RegisterAll(r, db)
|
||||
|
||||
addr := fmt.Sprintf(":%s", cfg.Port)
|
||||
|
||||
Reference in New Issue
Block a user