frostfs-qos/tagging/context.go
Dmitrii Stepanov 1fb8b137c5
[#2] tagging: Add grpc and context methods
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2025-01-28 14:29:36 +03:00

21 lines
458 B
Go

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
}