You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
339 B

  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "time"
  6. )
  7. func Logger(inner http.Handler, name string) http.Handler {
  8. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  9. start := time.Now()
  10. inner.ServeHTTP(w, r)
  11. log.Printf(
  12. "%s\t%s\t%s\t%s",
  13. r.Method,
  14. r.RequestURI,
  15. name,
  16. time.Since(start),
  17. )
  18. })
  19. }