go

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Go

Go

  1. Propagate the existing request context through downstream work.
  2. Use
    context.Background()
    only at process bootstrap or intentionally detached workers.
  3. Prefer explicit code and constructor injection.
  4. Avoid package-level mutable state.
  5. Wrap errors with useful context. Never silently ignore them.
  6. Match existing project patterns before adding helpers.
  7. Add tests for new behaviour.
  8. Avoid dependencies unless the standard library or installed packages fall short.
Completion: changed Go code preserves request context, has explicit dependencies and useful errors, follows local package patterns, and passes the narrowest relevant tests.
  1. 在下游工作中传递现有的请求 context。
  2. 仅在进程启动阶段或有意脱离请求上下文的工作任务中使用
    context.Background()
    。
  3. 优先使用显式依赖和构造函数注入。
  4. 避免使用包级可变状态。
  5. 使用有用的上下文包装错误。切勿静默忽略错误。
  6. 添加辅助函数之前,先遵循现有项目的模式。
  7. 为新行为添加测试。
  8. 除非标准库或已安装的包无法满足需求,否则避免引入依赖项。
完成标准:修改后的 Go 代码能够保留请求 context,具备显式依赖和有意义的错误处理,遵循本地包模式,并通过范围最窄的相关测试。