go-ethereum/common/context.go
Evgeny Danilenko 22fa4033e8
Event based pprof (#732)
* feature

* Save pprof to /tmp

---------

Co-authored-by: Jerry <jerrycgh@gmail.com>
2023-02-08 13:41:09 -08:00

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
}