parent
d98703610d
commit
d71b00e067
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -42,6 +43,7 @@ func GetPort() string {
|
||||||
func GetRate() (int, int) {
|
func GetRate() (int, int) {
|
||||||
rate := conf.Get("r").GetInt()
|
rate := conf.Get("r").GetInt()
|
||||||
burst := conf.Get("b").GetInt()
|
burst := conf.Get("b").GetInt()
|
||||||
|
log.Println("rate/burst:", rate, burst)
|
||||||
return rate, burst
|
return rate, burst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ func pipe(a, b net.Conn) {
|
||||||
|
|
||||||
func (s *Server) Pre(foo http.HandlerFunc) http.HandlerFunc {
|
func (s *Server) Pre(foo http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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()
|
defer can()
|
||||||
if err := s.limiter.Wait(ctx); err != nil {
|
if err := s.limiter.Wait(ctx); err != nil {
|
||||||
w.WriteHeader(http.StatusTooManyRequests)
|
w.WriteHeader(http.StatusTooManyRequests)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue