mirror of
https://github.com/ProtonMail/go-proton-api.git
synced 2025-12-23 23:57:50 -05:00
23 lines
588 B
Go
23 lines
588 B
Go
package proton
|
|
|
|
import "context"
|
|
|
|
type withClientKeyType struct{}
|
|
|
|
var withClientKey withClientKeyType
|
|
|
|
// WithClient marks this context as originating from the client with the given ID.
|
|
func WithClient(parent context.Context, clientID uint64) context.Context {
|
|
return context.WithValue(parent, withClientKey, clientID)
|
|
}
|
|
|
|
// ClientIDFromContext returns true if this context was marked as originating from a client.
|
|
func ClientIDFromContext(ctx context.Context) (uint64, bool) {
|
|
clientID, ok := ctx.Value(withClientKey).(uint64)
|
|
if !ok {
|
|
return 0, false
|
|
}
|
|
|
|
return clientID, true
|
|
}
|