update on the review comments
1. change ContextKeyModelId to ContextKeyModuleId 2. added ContextKeyTxnId to the constants.
This commit is contained in:
@@ -69,7 +69,7 @@ func setupLogger(t *testing.T, l level) string {
|
|||||||
model.ContextKeyTxnID,
|
model.ContextKeyTxnID,
|
||||||
model.ContextKeyMsgID,
|
model.ContextKeyMsgID,
|
||||||
model.ContextKeySubscriberID,
|
model.ContextKeySubscriberID,
|
||||||
model.ContextKeyModelID,
|
model.ContextKeyModuleID,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -204,9 +204,10 @@ func TestParseContextKey_ValidKeys(t *testing.T) {
|
|||||||
input string
|
input string
|
||||||
expected ContextKey
|
expected ContextKey
|
||||||
}{
|
}{
|
||||||
|
{"transaction_id", ContextKeyTxnID},
|
||||||
{"message_id", ContextKeyMsgID},
|
{"message_id", ContextKeyMsgID},
|
||||||
{"subscriber_id", ContextKeySubscriberID},
|
{"subscriber_id", ContextKeySubscriberID},
|
||||||
{"model_id", ContextKeyModelID},
|
{"module_id", ContextKeyModuleID},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
@@ -51,21 +51,22 @@ const (
|
|||||||
// ContextKeySubscriberID is the context key used to store and retrieve the subscriber ID in a request context.
|
// ContextKeySubscriberID is the context key used to store and retrieve the subscriber ID in a request context.
|
||||||
ContextKeySubscriberID ContextKey = "subscriber_id"
|
ContextKeySubscriberID ContextKey = "subscriber_id"
|
||||||
|
|
||||||
// ContextKeyModelID is the context key for storing and retrieving the model ID from a request context.
|
// ContextKeyModuleID is the context key for storing and retrieving the model ID from a request context.
|
||||||
ContextKeyModelID ContextKey = "model_id"
|
ContextKeyModuleID ContextKey = "module_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var contextKeys = map[string]ContextKey{
|
var contextKeys = map[string]ContextKey{
|
||||||
|
"transaction_id": ContextKeyTxnID,
|
||||||
"message_id": ContextKeyMsgID,
|
"message_id": ContextKeyMsgID,
|
||||||
"subscriber_id": ContextKeySubscriberID,
|
"subscriber_id": ContextKeySubscriberID,
|
||||||
"model_id": ContextKeyModelID,
|
"module_id": ContextKeyModuleID,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseContextKey converts a string into a valid ContextKey.
|
// ParseContextKey converts a string into a valid ContextKey.
|
||||||
func ParseContextKey(v string) (ContextKey, error) {
|
func ParseContextKey(v string) (ContextKey, error) {
|
||||||
key, ok := contextKeys[v]
|
key, ok := contextKeys[v]
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("invalid context key: %s", key)
|
return "", fmt.Errorf("invalid context key: %s", v)
|
||||||
}
|
}
|
||||||
return key, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user