Files
learning_go/ch14/1/ch14_1.go
lbenedar 589d2ae3d8 add ch14
2026-02-23 16:56:00 +03:00

25 lines
425 B
Go

package main
import (
"context"
"net/http"
"time"
)
type MsReq struct{}
func CreateTimeoutCtx(msReq time.Duration) func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
reqCtx := r.Context()
reqCtx = context.WithValue(reqCtx, MsReq{}, msReq)
r.WithContext(reqCtx)
h.ServeHTTP(w, r)
})
}
}
func main() {
}