mirror of https://github.com/XTLS/Xray-core
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.
25 lines
492 B
25 lines
492 B
package ctx |
|
|
|
import "context" |
|
|
|
type SessionKey int |
|
|
|
// ID of a session. |
|
type ID uint32 |
|
|
|
const ( |
|
idSessionKey SessionKey = 0 |
|
) |
|
|
|
// ContextWithID returns a new context with the given ID. |
|
func ContextWithID(ctx context.Context, id ID) context.Context { |
|
return context.WithValue(ctx, idSessionKey, id) |
|
} |
|
|
|
// IDFromContext returns ID in this context, or 0 if not contained. |
|
func IDFromContext(ctx context.Context) ID { |
|
if id, ok := ctx.Value(idSessionKey).(ID); ok { |
|
return id |
|
} |
|
return 0 |
|
}
|
|
|