timeouthandler.go 317 B

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