writing-go-code

Apply Go coding standards for functions, dependency injection, error handling, and interfaces.

2|Updated Aug 6, 2021
One-click install
npx skills add https://github.com/MrPointer/dotfiles --skill writing-go-code
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-go-code
Source: https://github.com/MrPointer/dotfiles/tree/main/.claude/skills/writing-go-code
Command: npx skills add https://github.com/MrPointer/dotfiles --skill writing-go-code

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill ensures your Go code adheres to established best practices, improving readability, maintainability, and robustness.

Core Features & Use Cases

  • Code Organization: Follows standard Go project structure for structs, interfaces, and constructors.
  • Dependency Injection: Enforces constructor-based dependency injection for better testability and modularity.
  • Idiomatic Error Handling: Guides on proper error wrapping and handling.
  • Mock Generation: Integrates with mockery for generating mock objects.
  • Use Case: When implementing a new feature in a Go application, use this Skill to guide the structure of your new types, functions, and their dependencies.

Quick Start

Apply Go coding standards when writing or modifying Go code.

Frequently Asked Questions about writing-go-code

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

FAQPage Schema
How do I structure dependency injection in Go for better testability?

Dependency injection in Go is best handled using constructor-based injection, passing dependencies into constructors to improve modularity and testability. This approach enforces clear code organization and ensures structs, interfaces, and constructors follow standard Go project structure.

What is the best way to handle errors idiomatically in Go code?

Idiomatic error handling in Go involves properly wrapping errors to maintain context as they propagate up the call stack. This ensures robust code by preserving the original error trace while adding meaningful information about where the failure occurred.

How do I generate mock objects for Go interfaces using mockery?

Generating mock objects with mockery involves integrating the tool into your Go project to automatically create mocks for your interfaces. This supports testability by allowing you to simulate dependencies in unit tests without requiring real implementations.

How do I implement standard Go project structure when writing new features?

Implementing a standard Go project structure requires organizing structs, interfaces, and constructors according to established coding standards. This ensures your new types, functions, and dependencies are readable, maintainable, and follow idiomatic Go conventions.

Can I use this Skill to enforce coding standards for modifying existing Go code?

Yes, this Skill applies Go coding standards to both writing and modifying Go code. It focuses on idiomatic implementation of functions, dependency injection, error handling, and interface usage while enforcing project-specific conventions for code organization and documentation.

Why does my Go code need constructor-based dependency injection?

Constructor-based dependency injection is needed in Go to achieve better testability and modularity. By injecting dependencies through constructors rather than using global state, you ensure components are loosely coupled and easily testable with mock objects.