Перенес необходимые изменения из лабораторной работы №2

This commit is contained in:
Grbisba
2026-11-06 14:27:27 +03:00
parent 0ab3a341aa
commit 4c066ff191
92 changed files with 7156 additions and 7 deletions
@@ -0,0 +1,18 @@
package middleware
import (
"context"
"net/http"
"time"
)
// RequestTimeout bounds database work and waiting for a pooled connection.
func RequestTimeout(timeout time.Duration) Middleware {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), timeout)
defer cancel()
next.ServeHTTP(w, r.WithContext(ctx))
})
}
}