mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 16:41:30 +00:00
34 lines
474 B
Go
34 lines
474 B
Go
package log
|
|
|
|
import (
|
|
"context"
|
|
"math/rand"
|
|
|
|
"github.com/sagernet/sing/common/random"
|
|
)
|
|
|
|
func init() {
|
|
random.InitializeSeed()
|
|
}
|
|
|
|
var idType = (*idContext)(nil)
|
|
|
|
type idContext struct {
|
|
context.Context
|
|
id uint32
|
|
}
|
|
|
|
func (c *idContext) Value(key any) any {
|
|
if key == idType {
|
|
return c
|
|
}
|
|
return c.Context.Value(key)
|
|
}
|
|
|
|
func ContextWithID(ctx context.Context) context.Context {
|
|
if ctx.Value(idType) != nil {
|
|
return ctx
|
|
}
|
|
return &idContext{ctx, rand.Uint32()}
|
|
}
|