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.
go-zero/rest/handler/timeouthandler.go

20 lines
364 B
Go

4 years ago
package handler
4 years ago
import (
"net/http"
"time"
)
const reason = "Request Timeout"
// TimeoutHandler returns the handler with given timeout.
4 years ago
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
4 years ago
}
}