mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-23 03:43:33 +02:00
079d0bd8a9
* Refactor log * Add new log methods * Fix logger test * Change all logging code * Clean up pathObj * Rebase to latest main * Remove invoking method name after the dot
25 lines
491 B
Go
25 lines
491 B
Go
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
|
|
}
|