[#2] tagging: Add grpc and context methods
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
f4d8ebf13d
commit
1fb8b137c5
5 changed files with 190 additions and 1 deletions
21
tagging/context.go
Normal file
21
tagging/context.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue