frostfs-qos/tagging/context.go

22 lines
458 B
Go
Raw Permalink Normal View History

package tagging
import "context"
type tagContextKeyType struct{}
var currentTagKey = tagContextKeyType{}
func ContextWithIOTag(parent context.Context, ioTag string) context.Context {
return context.WithValue(parent, currentTagKey, ioTag)
}
func IOTagFromContext(ctx context.Context) (string, bool) {
if ctx == nil {
panic("context must be non nil")
}
if tag, ok := ctx.Value(currentTagKey).(string); ok {
return tag, true
}
return "", false
}