add ch14
This commit is contained in:
24
ch14/1/ch14_1.go
Normal file
24
ch14/1/ch14_1.go
Normal file
@@ -0,0 +1,24 @@
|
||||
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() {
|
||||
|
||||
}
|
||||
3
ch14/1/go.mod
Normal file
3
ch14/1/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module gitea.local.lab/Lbenedar/learning_go/ch14/1
|
||||
|
||||
go 1.25.0
|
||||
Reference in New Issue
Block a user