go-defensive

Apply defensive programming patterns to mitigate Go coding pitfalls.

Updated Apr 16, 2026
One-click install
npx skills add https://github.com/HadiCherkaoui/opencode-config --skill go-defensive-hadicherkaoui
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-defensive
Source: https://github.com/HadiCherkaoui/opencode-config/tree/main/skills/golang/go-defensive
Command: npx skills add https://github.com/HadiCherkaoui/opencode-config --skill go-defensive-hadicherkaoui

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go projects frequently stumble on subtle correctness issues and maintenance headaches. This Skill codifies defensive programming patterns to reduce bugs and promote robust, readable code.

Core Features & Use Cases

  • Interface verification at compile time to catch mismatch errors early.
  • Copying slices and maps at boundaries to prevent unintended mutations.
  • Proper time handling with time.Time and time.Duration to avoid timing bugs.
  • Avoidance of mutable globals through dependency injection for testability.
  • Defer-based cleanup to ensure resources are released reliably.

Quick Start

Apply interface assertions, safe copy functions, time handling patterns, and defer-based cleanup to reinforce robust Go code.

Frequently Asked Questions about go-defensive

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent unintended mutations when passing Go slices and maps?

Implementing defensive programming patterns requires standard Go projects to apply compile-time interface assertions, safe data copies, time.Time and time.Duration usage, and dependency injection for testability.

How do I verify Go interface compliance at compile time?

Verify Go interface compliance at compile time by adding compile-time interface assertions to your structs. This catches mismatch errors early during the build process rather than at runtime.

What is the best way to handle time and avoid timing bugs in Go?

The best way to avoid timing bugs in Go is proper time handling using time.Time and time.Duration patterns. This prevents calculation errors and ensures duration logic remains clear and testable.

Why should I avoid mutable globals in Go projects?

Avoid mutable globals in Go projects to improve testability through dependency injection. Injecting dependencies replaces global state, making functions predictable and easier to test in isolation.

How do I ensure reliable resource cleanup in Go?

Ensure reliable resource cleanup in Go by using clear defer-based cleanup patterns. Deferring operations guarantees that resources are released consistently, even when a function exits early or encounters an error.