From 9fd4e69ce4a239d2996e9c20c2609b5f5e6fdb37 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 11 Jul 2019 11:58:46 +0300 Subject: [PATCH] Don't return a context from After* hooks --- example_instrumentation_test.go | 8 ++++---- redis.go | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/example_instrumentation_test.go b/example_instrumentation_test.go index 65ef59c..e128ae3 100644 --- a/example_instrumentation_test.go +++ b/example_instrumentation_test.go @@ -16,9 +16,9 @@ func (redisHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Co return ctx, nil } -func (redisHook) AfterProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) { +func (redisHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error { fmt.Printf("finished processing: <%s>\n", cmd) - return ctx, nil + return nil } func (redisHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) { @@ -26,9 +26,9 @@ func (redisHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) return ctx, nil } -func (redisHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) { +func (redisHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error { fmt.Printf("pipeline finished processing: %v\n", cmds) - return ctx, nil + return nil } func Example_instrumentation() { diff --git a/redis.go b/redis.go index 31dbea3..10200bb 100644 --- a/redis.go +++ b/redis.go @@ -22,10 +22,10 @@ func SetLogger(logger *log.Logger) { type Hook interface { BeforeProcess(ctx context.Context, cmd Cmder) (context.Context, error) - AfterProcess(ctx context.Context, cmd Cmder) (context.Context, error) + AfterProcess(ctx context.Context, cmd Cmder) error BeforeProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error) - AfterProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error) + AfterProcessPipeline(ctx context.Context, cmds []Cmder) error } type hooks struct { @@ -68,8 +68,7 @@ func (hs hooks) beforeProcess(ctx context.Context, cmd Cmder) (context.Context, func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) (context.Context, error) { var firstErr error for _, h := range hs.hooks { - var err error - ctx, err = h.AfterProcess(ctx, cmd) + err := h.AfterProcess(ctx, cmd) if err != nil && firstErr == nil { firstErr = err } @@ -109,8 +108,7 @@ func (hs hooks) beforeProcessPipeline(ctx context.Context, cmds []Cmder) (contex func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error) { var firstErr error for _, h := range hs.hooks { - var err error - ctx, err = h.AfterProcessPipeline(ctx, cmds) + err := h.AfterProcessPipeline(ctx, cmds) if err != nil && firstErr == nil { firstErr = err }