diff --git a/handlers/ratelimiter.go b/handlers/ratelimiter.go index 735c394..acfb0bb 100644 --- a/handlers/ratelimiter.go +++ b/handlers/ratelimiter.go @@ -13,7 +13,7 @@ func NewRateLimitHandler(l log.Logger, b *ratelimit.Bucket) func(h http.Handler) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { d := b.Take(1) if d > 0 { - l.Log("msg", "Rate limiting", "delay", d) + l.Log("msg", "Rate limiting", "delay", d, "remote_addr", r.RemoteAddr) time.Sleep(d) } diff --git a/handlers/statuspaths.go b/handlers/statuspaths.go index dc1f434..4c4d47f 100644 --- a/handlers/statuspaths.go +++ b/handlers/statuspaths.go @@ -7,19 +7,18 @@ import ( ) func NewHTTPStatusPaths(_ log.Logger, paths []string, httpStatus int) func(h http.Handler) http.Handler { - var actions = make(map[string]bool, len(paths)) + var pathMap = make(map[string]bool, len(paths)) for _, p := range paths { if p == "" { continue } - actions[p] = true + pathMap[p] = true } return func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - action := r.URL.Path[1:] - if _, exists := actions[action]; action != "" && exists { + if _, exists := pathMap[r.URL.Path]; exists { w.WriteHeader(httpStatus) return } diff --git a/main.go b/main.go index 3dfcb3e..de96cdf 100644 --- a/main.go +++ b/main.go @@ -135,7 +135,8 @@ func decorateHandler(l log.Logger, h http.Handler, b *ratelimit.Bucket) http.Han decorators = append( decorators, - handlers.NewHTTPStatusPaths(l, []string{"health", "health/"}, http.StatusOK), + // Defining "health" end-points. + handlers.NewHTTPStatusPaths(l, []string{"/health", "/"}, http.StatusOK), // Ignoring common foo requests handlers.NewHTTPStatusPaths(l, []string{"/favicon"}, http.StatusNotFound),