mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
19 lines
321 B
Go
19 lines
321 B
Go
|
package httphandler
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const reason = "Request 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)
|
||
|
} else {
|
||
|
return next
|
||
|
}
|
||
|
}
|
||
|
}
|