timeouthandler.go 364 B

12345678910111213141516171819
  1. package handler
  2. import (
  3. "net/http"
  4. "time"
  5. )
  6. const reason = "Request Timeout"
  7. // TimeoutHandler returns the handler with given timeout.
  8. func TimeoutHandler(duration time.Duration) func(http.Handler) http.Handler {
  9. return func(next http.Handler) http.Handler {
  10. if duration > 0 {
  11. return http.TimeoutHandler(next, duration, reason)
  12. }
  13. return next
  14. }
  15. }