From ec2ad4cf538232a2f3399358c2ac5410ff5afeb4 Mon Sep 17 00:00:00 2001 From: niuaniua <939085525@qq.com> Date: Thu, 13 Apr 2023 00:12:01 +0800 Subject: [PATCH] fix: iter would no longer be inited every time in the loop --- interceptors/logging/examples/zap/example_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interceptors/logging/examples/zap/example_test.go b/interceptors/logging/examples/zap/example_test.go index 88a7b0d77..d44a1a3ce 100644 --- a/interceptors/logging/examples/zap/example_test.go +++ b/interceptors/logging/examples/zap/example_test.go @@ -17,10 +17,10 @@ import ( func InterceptorLogger(l *zap.Logger) logging.Logger { return logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) { f := make([]zap.Field, 0, len(fields)/2) + iter := logging.Fields(fields).Iterator() for i := 0; i < len(fields); i += 2 { - i := logging.Fields(fields).Iterator() - if i.Next() { - k, v := i.At() + if iter.Next() { + k, v := iter.At() f = append(f, zap.Any(k, v)) } }