VOL-3507 Implement the device update queries in rw-core
Change-Id: I2e9de4935c12981ddb7f10924d629bcd0ec09ef5
diff --git a/rw_core/utils/core_utils.go b/rw_core/utils/core_utils.go
index 71d5acd..c080dc6 100644
--- a/rw_core/utils/core_utils.go
+++ b/rw_core/utils/core_utils.go
@@ -34,6 +34,9 @@
var (
// RPCContextKey for keeping rpc name as metadata
rpcContextKey = contextKey("rpc")
+
+ // fromTopicContextKey for keeping entity from which operation is requested as metadata
+ fromTopicContextKey = contextKey("fromTopic")
)
// ResponseCallback is the function signature for callbacks to execute after a response is received.
@@ -169,3 +172,26 @@
}
return targetCtx
}
+
+func WithFromTopicMetadataContext(ctx context.Context, fromTopic string) context.Context {
+ ctx = context.WithValue(ctx, fromTopicContextKey, fromTopic)
+ return ctx
+}
+
+func WithFromTopicMetadataFromContext(targetCtx, sourceCtx context.Context) context.Context {
+ if sourceCtx != nil {
+ if val, ok := sourceCtx.Value(fromTopicContextKey).(string); ok {
+ targetCtx = context.WithValue(targetCtx, fromTopicContextKey, val)
+ }
+ }
+ return targetCtx
+}
+
+func GetFromTopicMetadataFromContext(ctx context.Context) string {
+ if ctx != nil {
+ if val, ok := ctx.Value(fromTopicContextKey).(string); ok {
+ return val
+ }
+ }
+ return ""
+}