mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Add query to the context
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user