Skip to content

Commit e2d6be8

Browse files
committed
fix linter
1 parent 01844e6 commit e2d6be8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

hitless/example_hooks.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import (
88
"github.com/redis/go-redis/v9/internal"
99
)
1010

11+
// contextKey is a custom type for context keys to avoid collisions
12+
type contextKey string
13+
14+
const (
15+
startTimeKey contextKey = "start_time"
16+
)
17+
1118
// MetricsHook collects metrics about notification processing.
1219
type MetricsHook struct {
1320
NotificationCounts map[string]int64
@@ -30,15 +37,15 @@ func (mh *MetricsHook) PreHook(ctx context.Context, notificationType string, not
3037

3138
// Store start time in context for duration calculation
3239
startTime := time.Now()
33-
_ = context.WithValue(ctx, "start_time", startTime) // Context not used further
40+
_ = context.WithValue(ctx, startTimeKey, startTime) // Context not used further
3441

3542
return notification, true
3643
}
3744

3845
// PostHook records processing completion and any errors.
3946
func (mh *MetricsHook) PostHook(ctx context.Context, notificationType string, notification []interface{}, result error) {
4047
// Calculate processing duration
41-
if startTime, ok := ctx.Value("start_time").(time.Time); ok {
48+
if startTime, ok := ctx.Value(startTimeKey).(time.Time); ok {
4249
duration := time.Since(startTime)
4350
mh.ProcessingTimes[notificationType] = duration
4451
}

0 commit comments

Comments
 (0)