update for tech summit workshop

This commit is contained in:
David
2020-09-23 14:46:48 -04:00
parent a651b9cd73
commit a066ed3bd1
8 changed files with 149 additions and 4 deletions
+14 -3
View File
@@ -34,6 +34,17 @@ func (s *Server) setLimit(w http.ResponseWriter, r *http.Request) {
s.RateLimiter = rl
}
func (s *Server) handleClick(w http.ResponseWriter, r *http.Request) {
// Sleep for a random amount of time up to 100 milliseconds.
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
w.WriteHeader(http.StatusNoContent)
t := r.Context().Value("rate-limit-token").(*Token)
s.RateLimiter.Release(t)
return
}
func (s *Server) getData(w http.ResponseWriter, r *http.Request) {
data := []struct {
Item1 string
@@ -42,7 +53,7 @@ func (s *Server) getData(w http.ResponseWriter, r *http.Request) {
}{
{
Item1: "books",
Item2: "hotdogs",
Item2: "hot dogs",
Item3: "trinkets",
},
}
@@ -53,8 +64,8 @@ func (s *Server) getData(w http.ResponseWriter, r *http.Request) {
return
}
// Sleep for a random amount of time up to 5 seconds.
time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond)
// Sleep for a random amount of time up to 1 seconds.
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
w.Write(bytes)