master v0.5
bel 2019-11-06 18:07:38 -07:00
parent d98703610d
commit d71b00e067
2 changed files with 3 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package config
import (
"fmt"
"log"
"strings"
"time"
)
@ -42,6 +43,7 @@ func GetPort() string {
func GetRate() (int, int) {
rate := conf.Get("r").GetInt()
burst := conf.Get("b").GetInt()
log.Println("rate/burst:", rate, burst)
return rate, burst
}

View File

@ -164,7 +164,7 @@ func pipe(a, b net.Conn) {
func (s *Server) Pre(foo http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, can := context.WithTimeout(r.Context(), time.Second*time.Duration(config.GetTimeout()))
ctx, can := context.WithTimeout(r.Context(), time.Duration(config.GetTimeout()))
defer can()
if err := s.limiter.Wait(ctx); err != nil {
w.WriteHeader(http.StatusTooManyRequests)