You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
364 B
Go
20 lines
364 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
const reason = "Request Timeout"
|
|
|
|
// TimeoutHandler returns the handler with given timeout.
|
|
func TimeoutHandler(duration time.Duration) func(http.Handler) http.Handler {
|
|
return func(next http.Handler) http.Handler {
|
|
if duration > 0 {
|
|
return http.TimeoutHandler(next, duration, reason)
|
|
}
|
|
|
|
return next
|
|
}
|
|
}
|