What problem does it solve?
Go projects often suffer from subtle bugs due to interface mismatches, unsafe in-place modifications, improper resource cleanup, and poor time handling. This Skill provides a collection of defensive programming patterns to prevent these issues by enforcing compile-time checks, safe data handling, and reliable cleanup.
Core Features & Use Cases
- Verify interface compliance at compile time using zero-value assertions to catch mismatches early.
- Copy slices and maps at API boundaries to avoid exposing internal state.
- Use defer for cleanup to ensure resources are released reliably, even on early returns.
- Use time.Time and time.Duration for time values to avoid ambiguous numeric representations.
- Favor dependency injection over mutable globals to improve testability and robustness.
- Avoid embedding public structs; delegate explicitly to preserve API evolution.
Quick Start
Refactor a small Go module to apply interface verification, safe copying, and defer-based cleanup for robust production-grade code.