mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
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
|
|
}
|
|
}
|