Course Overview
Locked video preview

Paid video

Please purchase the course to watch.

Authentication and authorization

Rate-limiting logins

Here is a summary of the video transcript:

  • Introduction of IP Rate Limiting
    The video demonstrates how to implement an IP-based rate limiter in a Go web application. It uses an in-memory caching strategy to track request counts per IP address.

  • Using Otter for In-Memory Caching
    The implementation relies on Otter, a high-performance Go caching library. It enables efficient in-memory storage without adding external infrastructure components.

  • Avoiding Circular Dependencies
    The rate limiter middleware is placed in the routes package to prevent circular dependencies. This ensures proper architectural separation while maintaining access to route definitions.

  • Cache Configuration
    A cache is initialized with a maximum size of 1,000 entries and a 10-minute expiration time. The cache maps IP addresses (string) to hit counts (int32).

  • Rate Limiting Logic
    For each request, the client’s real IP is retrieved from the Echo context. If the IP is not present in the cache, it is added with an initial hit count of one.

  • Enforcing Request Limits
    If the number of hits for an IP is below the limit (10 requests), the counter is incremented. If the limit is exceeded, the user is redirected to the login page with an HTTP “Too Many Requests” status.

  • Middleware Integration
    The rate limiter is registered as middleware in the router. Since it follows the required Echo handler signature, it can be added alongside other middleware functions.

  • Next Steps
    The video concludes by planning to implement authentication middleware and integrate it into a complete authentication flow.