go-functions-methods

Enforce Go receiver selection, named returns, and safe defer usage.

15|Updated Mar 4, 2026
One-click install
npx skills add https://github.com/v0lka/skills --skill go-functions-methods
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-functions-methods
Source: https://github.com/v0lka/skills/tree/main/development/idiomatic-go/go-functions-methods
Command: npx skills add https://github.com/v0lka/skills --skill go-functions-methods

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go developers often struggle to write correct and maintainable functions and methods, suffering from inconsistent receiver choices, unclear return parameters, and unsafe defer usage. This Skill provides clear guidelines to improve correctness, readability, and maintainability of Go code.

Core Features & Use Cases

  • Enforces receiver type selection rules (pointer vs value) to reflect mutability and semantics.
  • Encourages named return parameters and avoids naked returns where clarity suffers.
  • Promotes using io.Reader (not filenames) to keep code flexible and testable.
  • Guides safe defer usage and captures semantics for closures and receivers.
  • Use Case: When implementing a new Go type with methods, apply these rules to prevent subtle bugs and enable easier testing.

Quick Start

Follow these guidelines when creating or refactoring a Go type to ensure proper receiver choice, named results, and safe defer usage.

Frequently Asked Questions about go-functions-methods

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

FAQPage Schema
When should I use pointer vs value receivers in Go methods?

Choose pointer receivers in Go methods when the method mutates the receiver or the type is large, and use value receivers for immutable, small types to reflect correct semantics and improve maintainability.

How do I use named return parameters in Go functions without reducing readability?

Use named return parameters in Go functions to clarify return values, but avoid naked returns in complex functions where they reduce readability. Named returns are best used to document function signatures and simplify defer blocks.

What is the best way to design Go functions for testability using io.Reader?

Design Go functions to accept io.Reader instead of filenames to keep code flexible and testable. This allows you to easily pass mock readers in unit tests rather than relying on actual file system operations.

How does defer work with closures and receivers in Go?

Go defer semantics capture function arguments and receiver values immediately. Use safe defer usage by capturing variables in closures carefully to prevent subtle bugs related to loop variables or mutated state during execution.

Why do my Go methods behave inconsistently across types and callers?

Inconsistent Go methods often stem from mixing pointer and value receivers across types. Enforcing strict receiver selection rules ensures consistent behavior across callers and prevents subtle bugs during real-world refactoring.