You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

20 lines
422 B

  1. package ratelimit_test
  2. import (
  3. "net/http"
  4. "time"
  5. "github.com/VojtechVitek/ratelimit"
  6. "github.com/VojtechVitek/ratelimit/memory"
  7. )
  8. func ExampleRequest() {
  9. middleware := ratelimit.Request(ratelimit.IP).Rate(30, time.Minute).LimitBy(memory.New())
  10. handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  11. w.Write([]byte("Hello World!"))
  12. })
  13. http.ListenAndServe(":3333", middleware(handler))
  14. }