go-interfaces

Guide Go interface design with small interfaces and compile-time verification.

2|Updated Feb 14, 2025
One-click install
npx skills add https://github.com/gofhir/validator --skill go-interfaces-gofhir
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-interfaces
Source: https://github.com/gofhir/validator/tree/main/.claude/skills/go-interfaces
Command: npx skills add https://github.com/gofhir/validator --skill go-interfaces-gofhir

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers design flexible, testable, and loosely coupled Go applications by focusing on interface design principles and demonstrating their application within the GoFHIR project.

Core Features & Use Cases

  • Interface Design Principles: Learn best practices like small interfaces and defining them where used.
  • GoFHIR Project Examples: See concrete interface definitions from the GoFHIR validator and FHIRPath evaluator.
  • Use Case: When building a new service in Go, use this Skill to understand how to define clear contracts between components, making your code easier to maintain and test.

Quick Start

Explain the principle of defining interfaces where they are used in Go.

Frequently Asked Questions about go-interfaces

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

FAQPage Schema
How do I design effective Go interfaces for API contracts?

Go interfaces should be defined where they are consumed, not where they are implemented. This principle keeps interfaces small, focused, and decoupled from concrete types, resulting in flexible and testable API contracts.

What is the best way to structure FHIR API contracts in Golang?

Structuring FHIR API contracts in Golang involves defining small, consumer-specific interfaces for components like validators and FHIRPath evaluators. This methodology ensures loose coupling and robust API design through compile-time verification.

How do I verify Go interface implementations at compile time?

Verify Go interface implementations at compile time by assigning a nil pointer of your type to an interface variable, such as `var _ MyInterface = (*MyType)(nil)`. This technique guarantees concrete types satisfy API contracts before runtime.

Why define Go interfaces where they are used instead of where they are implemented?

Defining Go interfaces where they are used prevents premature abstraction and tight coupling. This consumer-driven approach ensures contracts remain minimal, directly supporting the exact functionality required by the calling code without imposing unnecessary dependencies.

When should I use non-operation implementations for Go interfaces?

Use non-operation implementations for Go interfaces to verify type compatibility during compilation without adding runtime logic. This technique validates that your structs satisfy API contracts safely and explicitly, catching design errors early.