Skip to content

Commit

Permalink
Consistency, logger as first argument on all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynom committed Apr 26, 2017
1 parent eb29716 commit eb1a02d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion handlers/ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/juju/ratelimit"
)

func NewRateLimitHandler(b *ratelimit.Bucket, l log.Logger) func(h http.Handler) http.Handler {
func NewRateLimitHandler(l log.Logger, b *ratelimit.Bucket) func(h http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
d := b.Take(1)
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func main() {
"allowed_hosts", allowedHosts.String(),
"allowed_params", allowedImaginaryParams.String(),
"allowed_actions", allowedImaginaryActions.String(),
"path_to_strip", pathSegmentToStrip,
"imaginary_backend", imaginaryURL,
)

Expand All @@ -71,7 +72,7 @@ func main() {

s := &http.Server{
Addr: fmt.Sprintf(":%d", listenPort),
Handler: decorateHandler(proxy, rlBucket, logger),
Handler: decorateHandler(logger, proxy, rlBucket),
ReadHeaderTimeout: 2 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
Expand Down Expand Up @@ -99,7 +100,7 @@ func newProxy(l log.Logger, backend *url.URL) *httputil.ReverseProxy {

type httpHandler func(h http.Handler) http.Handler

func decorateHandler(h http.Handler, b *ratelimit.Bucket, l log.Logger) http.Handler {
func decorateHandler(l log.Logger, h http.Handler, b *ratelimit.Bucket) http.Handler {
decorators := []httpHandler{
handlers.NewValidateURLParameter(l, allowedHosts),
}
Expand Down Expand Up @@ -135,7 +136,7 @@ func decorateHandler(h http.Handler, b *ratelimit.Bucket, l log.Logger) http.Han
decorators = append(
decorators,
handlers.NewIgnoreFaviconRequests(),
handlers.NewRateLimitHandler(b, l),
handlers.NewRateLimitHandler(l, b),
)

var handler http.Handler = h
Expand Down

0 comments on commit eb1a02d

Please sign in to comment.