go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/quota/examples/ratelimit/README.md (about)

     1  # Quota Library Rate Limit Example
     2  
     3  This example shows how to integrate the quota library into a service which uses
     4  the LUCI server framework (but note that the only hard requirement is that the
     5  `redisconn` library has been configured with a redis service.
     6  
     7  ## Usage
     8  
     9  First, run `redis-server` locally (or... somewhere at least). It should be
    10  version 5.1 at minimum, though later versions _should_ work.
    11  
    12  Next, run this example server, pointing it at your redis service.
    13  ```shell
    14  $ go run . -redis-addr localhost:6379 &
    15  <observe logs, wait for the server to start>
    16  ```
    17  
    18  This example creates a very simply policy (Default 10, Limit 60, refill 10 every
    19  12 seconds), and only maintains a single account.
    20  
    21  You can exercise the quota by hitting the `/global-rate-limit-endpoint` on this
    22  local server, e.g.
    23  
    24  ```shell
    25  $ curl http://localhost:8800/global-rate-limit-endpoint
    26  <observe logs, expected 200 OK>
    27  $ curl http://localhost:8800/global-rate-limit-endpoint
    28  <observe logs, expected 429 Rate Limit Exceeded>
    29  ```
    30  
    31  You can also reset the quota to the default (10) by hitting the
    32  `/global-rate-limit-reset` endpoint.