| 1 |
package proton |
| 2 |
|
| 3 |
import "context" |
| 4 |
|
| 5 |
type withClientKeyType struct{} |
| 6 |
|
| 7 |
var withClientKey withClientKeyType |
| 8 |
|
| 9 |
// WithClient marks this context as originating from the client with the given ID. |
| 10 |
func WithClient(parent context.Context, clientID uint64) context.Context { |
| 11 |
return context.WithValue(parent, withClientKey, clientID) |
| 12 |
} |
| 13 |
|
| 14 |
// ClientIDFromContext returns true if this context was marked as originating from a client. |
| 15 |
func ClientIDFromContext(ctx context.Context) (uint64, bool) { |
| 16 |
clientID, ok := ctx.Value(withClientKey).(uint64) |
| 17 |
if !ok { |
| 18 |
return 0, false |
| 19 |
} |
| 20 |
|
| 21 |
return clientID, true |
| 22 |
} |