NewTimeoutMiddleware returns a new timeout middleware that returns a 503 Service Unavailable using the http.TimeoutHandler. Note also that the middleware disables the http server write timeout to ensure the two timeouts don't conflict. We disable the server write timeout b/c it's behavior may be uni
(dt time.Duration, msg string, log log.Logger)
| 25 | // - returns a 503 Service Unavailable with the provided message |
| 26 | // - buffers response in memory which may be undesirable for large responses |
| 27 | func NewTimeoutMiddleware(dt time.Duration, msg string, log log.Logger) Func { |
| 28 | return func(next http.Handler) http.Handler { |
| 29 | return &timeoutHandler{ |
| 30 | log: log, |
| 31 | handler: http.TimeoutHandler(next, dt, msg), |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | type timeoutHandler struct { |
| 37 | log log.Logger |
no outgoing calls