style(go): 合并连续变量声明并明确规范约束

This commit is contained in:
zhangdeman committed 2026-11-27 23:36:02 -08:00
1 parent 2492251a89
commit 5287321ca2
8 files changed
+42 -126

No files matched your search

+11 -33
View File
@@ -46,9 +46,7 @@ func (h *Hook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
return func(ctx context.Context, cmd redis.Cmder) error {
var (
begin = time.Now()
)
var (
err = next(ctx, cmd)
err = next(ctx, cmd)
)
h.record(ctx, cmd, time.Since(begin), err)
return err
@@ -61,12 +59,8 @@ func (h *Hook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
func (h *Hook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {
return func(ctx context.Context, cmds []redis.Cmder) error {
var (
begin = time.Now()
)
var (
err = next(ctx, cmds)
)
var (
begin = time.Now()
err = next(ctx, cmds)
elapsed = time.Since(begin)
)
for _, cmd := range cmds {
@@ -80,31 +74,15 @@ func (h *Hook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.Process
// 入参:ctx 为可信诊断上下文,cmd 为原生命令,elapsed 为执行耗时,resultErr 为当前命令真实结果。
func (h *Hook) record(ctx context.Context, cmd redis.Cmder, elapsed time.Duration, resultErr error) {
var (
args = cmd.Args()
)
var (
result any
)
var (
args = cmd.Args()
result any
loggedArgs any
)
var (
hidden bool
)
var (
status = "success"
)
var (
name = strings.ToLower(cmd.Name())
)
var (
method reflect.Value
)
var (
values []reflect.Value
)
var (
fields []zap.Field
hidden bool
status = "success"
name = strings.ToLower(cmd.Name())
method reflect.Value
values []reflect.Value
fields []zap.Field
)
if h.logger == nil {
return
+8 -24
View File
@@ -17,16 +17,10 @@ import (
// TestNativePipelineObservationPreservesData 验证 Pipeline 逐条对应记录,日志脱敏不修改执行参数和返回正文。
func TestNativePipelineObservationPreservesData(t *testing.T) {
var (
client = redisserver.New(t, 3)
)
var (
client = redisserver.New(t, 3)
core, logs = observer.New(zap.InfoLevel)
)
var (
ctx = context.Background()
)
var (
value = `{"nested":{"token":"private-token"},"data":"kept"}`
ctx = context.Background()
value = `{"nested":{"token":"private-token"},"data":"kept"}`
)
client.AddHook(New(zap.New(core), "cache"))
var (
@@ -34,9 +28,7 @@ func TestNativePipelineObservationPreservesData(t *testing.T) {
)
pipeline.Set(ctx, "safe-key", value, 0)
var (
get = pipeline.Get(ctx, "safe-key")
)
var (
get = pipeline.Get(ctx, "safe-key")
missing = pipeline.Get(ctx, "missing-key")
)
if _, err := pipeline.Exec(ctx); !errors.Is(err, redis.Nil) {
@@ -71,18 +63,10 @@ func TestNativePipelineObservationPreservesData(t *testing.T) {
func TestHookObservesReturnedError(t *testing.T) {
var (
core, logs = observer.New(zap.InfoLevel)
)
var (
hook = New(zap.New(core), "cache")
)
var (
cmd = redis.NewStringCmd(context.Background(), "get", "safe-key")
)
var (
calls int
)
var (
process = hook.ProcessHook(func(context.Context, redis.Cmder) error { calls++; return context.Canceled })
hook = New(zap.New(core), "cache")
cmd = redis.NewStringCmd(context.Background(), "get", "safe-key")
calls int
process = hook.ProcessHook(func(context.Context, redis.Cmder) error { calls++; return context.Canceled })
)
if err := process(context.Background(), cmd); !errors.Is(err, context.Canceled) {
t.Fatalf("error changed: %v", err)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.