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.
 
 
 

25 lines
438 B

  1. package main
  2. import (
  3. "net/http"
  4. "time"
  5. "github.com/VojtechVitek/ratelimit"
  6. )
  7. // curl -v http://localhost:3333
  8. func main() {
  9. middleware := ratelimit.Throttle(1)
  10. http.ListenAndServe(":3333", middleware(http.HandlerFunc(Work)))
  11. }
  12. func Work(w http.ResponseWriter, r *http.Request) {
  13. w.Write([]byte("working hard...\n\n"))
  14. if f, ok := w.(http.Flusher); ok {
  15. f.Flush()
  16. }
  17. time.Sleep(10 * time.Second)
  18. w.Write([]byte("done"))
  19. }