2022-09-12 21:05:34 +00:00
|
|
|
//go:build go1.7
|
2016-09-15 03:24:51 +00:00
|
|
|
// +build go1.7
|
|
|
|
|
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2018-12-16 03:38:51 +00:00
|
|
|
// Get retrieves a value from the request context
|
2016-09-15 03:24:51 +00:00
|
|
|
func Get(r *http.Request, key interface{}) interface{} {
|
|
|
|
return r.Context().Value(key)
|
|
|
|
}
|
|
|
|
|
2018-12-16 03:38:51 +00:00
|
|
|
// Set stores a value on the request context
|
2016-09-15 03:24:51 +00:00
|
|
|
func Set(r *http.Request, key, val interface{}) *http.Request {
|
|
|
|
if val == nil {
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.WithContext(context.WithValue(r.Context(), key, val))
|
|
|
|
}
|
|
|
|
|
2018-12-16 03:38:51 +00:00
|
|
|
// Clear is a null operation, since this is handled automatically in Go > 1.7
|
2020-05-26 02:46:36 +00:00
|
|
|
func Clear(r *http.Request) {}
|