Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

25 righe
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. }