Restructure all http related files
Moving all http related functions and helpers into a new http submodule
This commit is contained in:
parent
0a0c185c06
commit
18bf623114
4 changed files with 4 additions and 4 deletions
19
http/context.go
Normal file
19
http/context.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ContextValsMiddleware(pairs map[any]any) HandlerBuilder {
|
||||
return func(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
for key, val := range pairs {
|
||||
ctx = context.WithValue(ctx, key, val)
|
||||
}
|
||||
newRequest := r.WithContext(ctx)
|
||||
h.ServeHTTP(w, newRequest)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue