mihomo/listener/sing/context.go
2022-12-05 10:12:53 +08:00

24 lines
490 B
Go

package sing
import (
"context"
"github.com/Dreamacro/clash/adapter/inbound"
)
type contextKey string
var ctxKeyAdditions = contextKey("Additions")
func WithAdditions(ctx context.Context, additions ...inbound.Addition) context.Context {
return context.WithValue(ctx, ctxKeyAdditions, additions)
}
func getAdditions(ctx context.Context) []inbound.Addition {
if v := ctx.Value(ctxKeyAdditions); v != nil {
if a, ok := v.([]inbound.Addition); ok {
return a
}
}
return nil
}