-
Notifications
You must be signed in to change notification settings - Fork 902
/
Copy pathcontext.go
34 lines (25 loc) · 971 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (C) MongoDB, Inc. 2025-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package driverutil
import "context"
type ContextKey string
const (
ContextKeyHasMaxTimeMS ContextKey = "hasMaxTimeMS"
ContextKeyRequestID ContextKey = "requestID"
)
func WithValueHasMaxTimeMS(parentCtx context.Context, val bool) context.Context {
return context.WithValue(parentCtx, ContextKeyHasMaxTimeMS, val)
}
func WithRequestID(parentCtx context.Context, requestID int32) context.Context {
return context.WithValue(parentCtx, ContextKeyRequestID, requestID)
}
func HasMaxTimeMS(ctx context.Context) bool {
return ctx.Value(ContextKeyHasMaxTimeMS) != nil
}
func GetRequestID(ctx context.Context) (int32, bool) {
val, ok := ctx.Value(ContextKeyRequestID).(int32)
return val, ok
}