go-code-review

โดย openshift

ตรวจสอบโค้ด Go สำหรับรูปแบบสำนวน การจัดการข้อผิดพลาด ความปลอดภัยในการทำงานพร้อมกัน และข้อผิดพลาดทั่วไป ใช้เมื่อตรวจสอบไฟล์ .go ตรวจสอบการจัดการข้อผิดพลาด…

npx skills add https://github.com/openshift/lightspeed-operator --skill go-code-review

Go Code Review

Quick Reference

Issue TypeReference
Missing error checks, wrapped errorsreferences/error-handling.md
Race conditions, channel misusereferences/concurrency.md
Interface pollution, namingreferences/interfaces.md
Resource leaks, defer misusereferences/common-mistakes.md

Review Checklist

  • All errors are checked (no _ = err)
  • Errors wrapped with context (fmt.Errorf("...: %w", err))
  • Resources closed with defer immediately after creation
  • No goroutine leaks (channels closed, contexts canceled)
  • Interfaces defined by consumers, not producers
  • Interface names end in -er (Reader, Writer, Handler)
  • Exported names have doc comments
  • No naked returns in functions > 5 lines
  • Context passed as first parameter
  • Mutexes protect shared state, not methods

Kubernetes Operator Specific

  • Owner references set with controllerutil.SetControllerReference()
  • Finalizers added/removed safely (check for DeletionTimestamp)
  • Context propagated through reconcile loops
  • Client errors handled (distinguish NotFound vs other errors)
  • Status updates separate from spec changes
  • Resource watching pattern: Owned resources tracked via ResourceVersion, external resources use explicit watchers (see internal/controller/watchers/)
  • Reconcile functions are idempotent (safe to call multiple times)
  • Resource updates check semantic equality first (apiequality.Semantic.DeepEqual)
  • Return ctrl.Result{Requeue: true} for transient issues, errors for permanent failures
  • RBAC markers (//+kubebuilder:rbac) present for all resource access in controllers

When to Load References

  • Reviewing error return patterns → error-handling.md
  • Reviewing goroutines/channels → concurrency.md
  • Reviewing type definitions → interfaces.md
  • General Go review → common-mistakes.md

Review Questions

  1. Are all error returns checked and wrapped?
  2. Are goroutines properly managed with context cancellation?
  3. Are resources (files, connections) closed with defer?
  4. Are interfaces minimal and defined where used?

Valid Patterns (Do NOT Flag)

These patterns are acceptable and should NOT be flagged as issues:

  • _ = err with reason comment - Intentionally ignored errors with explanation
    _ = conn.Close() // Best effort cleanup, already handling primary error
    
  • Empty interface interface{} - For truly generic code (pre-generics codebases)
  • Naked returns in short functions - Acceptable in functions < 5 lines with named returns
  • Channel without close - When consumer stops via context cancellation, not channel close
  • Mutex protecting struct fields - Even if accessed only via methods, this is correct encapsulation
  • //nolint directives with reason - Acceptable when accompanied by explanation
    //nolint:errcheck // Error logged but not returned per API contract
    
  • Defer in loop - When function scope cleanup is intentional (e.g., processing files in batches)

Context-Sensitive Rules

Only flag these issues when the specific conditions apply:

IssueFlag ONLY IF
Missing error checkError return is actionable (can retry, log, or propagate)
Goroutine leakNo context cancellation path exists for the goroutine
Missing deferResource isn't explicitly closed before next acquisition or return
Interface pollutionInterface has > 1 method AND only one consumer exists

Skills เพิ่มเติมจาก openshift

openshift-docs
openshift
ค้นหาและอ่านเอกสารประกอบ OpenShift Container Platform ในรูปแบบ markdown ใช้เมื่อผู้ใช้ถามเกี่ยวกับฟีเจอร์ การกำหนดค่า การติดตั้ง… ของ OpenShift
triage-leaked-infra
openshift
ประเมินว่า AWS VPC หรือชุดโครงสร้างพื้นฐานจาก HyperShift CI ปลอดภัยที่จะลบหรือไม่ ใช้เมื่อผู้ใช้วาง cleanleaked output และถามว่า 'ลบอันนี้ได้ไหม?', 'มัน...
openshift-expert
openshift
ผู้เชี่ยวชาญด้านแพลตฟอร์ม OpenShift และ Kubernetes ที่มีความรู้เชิงลึกเกี่ยวกับสถาปัตยกรรมคลัสเตอร์ โอเปอเรเตอร์ เครือข่าย พื้นที่จัดเก็บข้อมูล การแก้ไขปัญหา และไปป์ไลน์ CI/CD ใช้…
Konflux Archived PipelineRuns
openshift
เข้าถึง Konflux PipelineRuns, TaskRuns และบันทึกพ็อดที่ถูกเก็บถาวรผ่าน KubeArchive ใช้โดยอัตโนมัติเมื่อตรวจสอบผลลัพธ์ของ Konflux PipelineRun หรือสืบสวน...
backport
openshift
ย้อนกลับคอมมิตหรือ PR จาก main ไปยัง release branch ใช้เมื่อผู้ใช้ขอให้ย้อนกลับ, cherry-pick, หรือพอร์ตการเปลี่ยนแปลงระหว่าง branch หรือเมื่อกำลังแก้ไข…
rebase
openshift
รีเบสสาขาปัจจุบันไปยังสาขาหลัก แก้ไขข้อขัดแย้งทั้งหมด และตรวจสอบว่า lint, i18n และ build ผ่าน ใช้เมื่อผู้ใช้ขอให้รีเบส อัปเดต หรือซิงค์…
Build CPO Image
openshift
สร้างและพุชอิมเมจคอนเทนเนอร์ control-plane-operator ใช้โดยอัตโนมัติเมื่อทดสอบการเปลี่ยนแปลง CPO ที่ต้องปรับใช้กับคลัสเตอร์ที่ใช้งานจริง
find-complexity
openshift
ค้นหาฟังก์ชันและเมธอดที่มีความซับซ้อนของไซโคลเมติกสูง ความยาวมากเกินไป หรือมีพารามิเตอร์มากเกินไป ใช้เมื่อผู้ใช้ขอให้ค้นหาโค้ดที่ซับซ้อน ความซับซ้อน…