golang-structs-interfaces

Enforce small consumer-defined interfaces and concrete constructor returns in Go type design.

Updated May 28, 2026
One-click install
npx skills add https://github.com/vanstinator/semantic-search --skill golang-structs-interfaces-vanstinator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-structs-interfaces
Source: https://github.com/vanstinator/semantic-search/tree/main/.agents/skills/golang-structs-interfaces
Command: npx skills add https://github.com/vanstinator/semantic-search --skill golang-structs-interfaces-vanstinator

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents common Go design issues by guiding you to choose the right interface boundaries, struct composition patterns, and receiver/value semantics so your code stays clear, testable, and correct.

Core Features & Use Cases

  • Interface design guidance: Keep interfaces small (1–3 methods), define them in the consumer package, and use compile-time checks for contract safety.
  • Constructor and DI patterns: Accept dependencies via interfaces but return concrete structs from constructors for clarity.
  • Robust implementation practices: Use comma-ok type assertions, optional capability via type assertions, useful zero values, correct embed vs named-field decisions, serialization field tags, and consistent pointer vs value receivers.

Quick Start

Ask the AI: Design my Go types for a notification service by defining the right small interfaces, returning concrete structs from constructors, choosing embedding vs named fields, and ensuring safe type assertions for event payload handling.

Frequently Asked Questions about golang-structs-interfaces

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

FAQPage Schema
How do I design small Go interfaces for dependency injection?

When designing Go structs and interfaces, return concrete struct types from constructors while accepting dependencies via interfaces. This approach provides clarity in type initialization while still leveraging interface flexibility for dependency injection and mocking during testing.

What is the best way to handle pointer vs value receivers in Go struct design?

Consistent pointer vs value receiver usage in Go struct design requires applying uniformity rules across all methods on a type. Choose value receivers for small immutable data and pointer receivers for large structs or state mutation, ensuring useful zero-value structs and preventing receiver semantic conflicts.

How do I implement compile-time interface verification in Go?

Compile-time interface verification in Go uses var _ InterfaceName = (*StructType)(nil) checks to enforce contract safety. This guarantees your concrete structs satisfy the required interface methods during compilation rather than discovering implementation gaps at runtime.

When should I use embedding vs named fields in Go struct composition?

Choose embedding in Go struct composition to promote fields and methods directly, or use named fields when avoiding method shadowing and maintaining explicit access paths is necessary for clear dependency boundaries and serialization tag control.