You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
456 B
20 lines
456 B
4 years ago
|
package query
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
)
|
||
|
|
||
|
type ctxQueryKey struct{}
|
||
|
|
||
|
// GetFromContext function extracts the request data from context
|
||
|
func GetFromContext(ctx context.Context) (q *Query, ok bool) {
|
||
|
q, ok = ctx.Value(ctxQueryKey{}).(*Query)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// WithContext function creates the new context with request data
|
||
|
func WithContext(ctx context.Context, q *Query) (withQuery context.Context) {
|
||
|
withQuery = context.WithValue(ctx, ctxQueryKey{}, q)
|
||
|
return
|
||
|
}
|