1234567891011121314151617181920212223 |
- package util
- import (
- "context"
- "net/http"
- )
- // ContextKey context key type
- type ContextKey string
- // ContextGet get from context
- func ContextGet(ctx context.Context, key interface{}) interface{} {
- return ctx.Value(key)
- }
- // ContextSet set to context
- func ContextSet(r *http.Request, key, val interface{}) *http.Request {
- if val == nil {
- return r
- }
- return r.WithContext(context.WithValue(r.Context(), key, val))
- }
|