mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
32 lines
499 B
Go
32 lines
499 B
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
|
|
unique "github.com/ethereum/go-ethereum/common/set"
|
|
)
|
|
|
|
type key struct{}
|
|
|
|
var (
|
|
labelsKey key
|
|
)
|
|
|
|
func WithLabels(ctx context.Context, labels ...string) context.Context {
|
|
if len(labels) == 0 {
|
|
return ctx
|
|
}
|
|
|
|
labels = append(labels, Labels(ctx)...)
|
|
|
|
return context.WithValue(ctx, labelsKey, unique.Deduplicate(labels))
|
|
}
|
|
|
|
func Labels(ctx context.Context) []string {
|
|
labels, ok := ctx.Value(labelsKey).([]string)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
return labels
|
|
}
|