ratelimit

command
v0.0.0-...-96b6dcb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Quota Library Rate Limit Example

This example shows how to integrate the quota library into a GAE service. Not intended to be run on App Engine. A GAE demo can be found under examples/appengine/quota.

Usage

Startup:

$ go run .&
<observe logs, wait for the server to start>

Verify that rate limiting works:

$ curl http://localhost:8800/global-rate-limit-endpoint
<observe logs, expected 200 OK>
$ curl http://localhost:8800/global-rate-limit-endpoint
<observe logs, expected 429 Rate Limit Exceeded>
<wait 60 seconds>
$ curl http://localhost:8800/global-rate-limit-endpoint
<observe logs, expected 200 OK>

Verify that resetting quota works:

$ curl http://localhost:8800/global-rate-limit-reset
<observe logs, expected 200 OK>
$ curl http://localhost:8800/global-rate-limit-endpoint
<observe logs, expected 200 OK>
$ curl http://localhost:8800/global-rate-limit-endpoint
<observe logs, expected 429 Rate Limit Exceeded>

Verify that multiple resets don't stack:

$ curl http://localhost:8800/global-rate-limit-reset
<observe logs, expected 200 OK>
$ curl http://localhost:8800/global-rate-limit-reset
<observe logs, expected 200 OK>
$ curl http://localhost:8800/global-rate-limit-endpoint
<observe logs, expected 200 OK>
$ curl http://localhost:8800/global-rate-limit-endpoint
<observe logs, expected 429 Rate Limit Exceeded>

Documentation

Overview

Package main contains a binary demonstrating how to use the server/quota module to implement rate limiting for requests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL