Skip to content

Commit

Permalink
add newlines to logs (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Homulvas authored May 23, 2024
1 parent 9f5d34d commit 11f0dae
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (r *Ratelimiter) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
client := http.Client{}
newReq, err := http.NewRequest(http.MethodGet, r.url, nil)
if err != nil {
_, _ = os.Stderr.WriteString(fmt.Sprintf("error creating request: %v", err))
_, _ = fmt.Fprintf(os.Stderr, "ratelimiter middleware: error creating request: %v\n", err)
r.next.ServeHTTP(rw, req)
return
}
newReq.Header = req.Header

resp, err := client.Do(newReq)
if err != nil {
_, _ = os.Stderr.WriteString(fmt.Sprintf("error making request: %v", err))
_, _ = fmt.Fprintf(os.Stderr, "ratelimiter middleware: error making request: %v\n", err)
r.next.ServeHTTP(rw, req)
return
}
Expand All @@ -64,9 +64,8 @@ func (r *Ratelimiter) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
http.Error(rw, "Too many requests", http.StatusTooManyRequests)
return
}
_, _ = os.Stderr.WriteString("dry run: too many requests")
_, _ = fmt.Fprintf(os.Stderr, "ratelimiter middleware: dry run: too many requests\n")
}

_, _ = fmt.Fprintf(os.Stdout, "ratelimiter response: %v\n", resp.Status)
r.next.ServeHTTP(rw, req)
}

0 comments on commit 11f0dae

Please sign in to comment.