From bfcd99074f2b8db1adcf9bd8facf612277847282 Mon Sep 17 00:00:00 2001 From: sacha-froment-ext Date: Tue, 29 Sep 2020 09:49:28 +0200 Subject: [PATCH] fix review 2 * add interface validation at compile time * remove useless helper func Signed-off-by: sacha-froment-ext --- contrib/go-redis/redis.v8/redis.go | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/contrib/go-redis/redis.v8/redis.go b/contrib/go-redis/redis.v8/redis.go index 180932daa1..291ab5e1e0 100644 --- a/contrib/go-redis/redis.v8/redis.go +++ b/contrib/go-redis/redis.v8/redis.go @@ -27,6 +27,8 @@ type datadogHook struct { *params } +var _ redis.Hook = (*datadogHook)(nil) + // params holds the tracer and a set of parameters which are recorded with every trace. type params struct { host string @@ -135,28 +137,8 @@ func (ddh *datadogHook) AfterProcessPipeline(ctx context.Context, cmds []redis.C func commandsToString(cmds []redis.Cmder) string { var b bytes.Buffer for _, cmd := range cmds { - b.WriteString(cmderToString(cmd)) + b.WriteString(cmd.String()) b.WriteString("\n") } return b.String() } - -func cmderToString(cmd redis.Cmder) string { - // We want to support multiple versions of the go-redis library. In - // older versions Cmder implements the Stringer interface, while in - // newer versions that was removed, and this String method which - // sometimes returns an error is used instead. By doing a type assertion - // we can support both versions. - if stringer, ok := cmd.(fmt.Stringer); ok { - return stringer.String() - } - - args := cmd.Args() - if len(args) == 0 { - return "" - } - if str, ok := args[0].(string); ok { - return str - } - return "" -}