go-dev-guidelines
This skill should be used when writing, refactoring, or testing Go code. It provides idiomatic Go development patterns, TDD-based workflows, project structure conventions, and testing best practices using testify/require and mockery. Activate this skill when creating new Go features, services, packages, tests, or when setting up new Go projects.
Install
mkdir -p .claude/skills/go-dev-guidelines && curl -L -o skill.zip "https://mcp.directory/api/skills/download/200" && unzip -o skill.zip -d .claude/skills/go-dev-guidelines && rm skill.zipInstalls to .claude/skills/go-dev-guidelines
About this skill
Go Development Guidelines
Overview
This skill provides comprehensive guidelines for idiomatic Go development with a Test-Driven Development (TDD) approach. Follow these patterns when writing Go code, creating tests, organizing projects, or refactoring existing code.
Quick Start Checklists
New Go Feature Checklist
When implementing a new feature in an existing Go project:
- Define interface - Create small, focused interface in appropriate package
- Write tests first - Create
*_test.gofile with testify/require tests - Generate mocks - Use mockery to generate mocks in
mocks/subfolder - Implement logic - Write the implementation to satisfy tests
- Handle errors - Ensure all errors are explicitly handled
- Add integration tests - Test the feature end-to-end if applicable
- Run go vet & gofmt - Ensure code meets Go standards
- Update documentation - Add godoc comments for exported types/functions
New Go Service/Package Checklist
When creating a new Go service or package from scratch:
- Setup project structure - Use standard Go layout (
/cmd,/internal,/pkg) - Initialize module - Run
go mod initwith appropriate module path - Define core interfaces - Start with small, focused interfaces
- Write tests first - Follow TDD approach for all business logic
- Implement with DI - Use dependency injection for testability
- Add logging - Include structured logging for observability
- Configure graceful shutdown - Implement proper cleanup for services
- Document package - Add package-level godoc and README
Core Principles
Follow these seven core principles for all Go development:
1. Follow Test-Driven Development (TDD)
Write tests before implementation. Tests should be easy to read and favor verbosity over abstraction.
2. Use testify/require for Unit Tests
All unit tests must use github.com/stretchr/testify/require for assertions.
3. Use Mockery for Mocks
Generate mocks using mockery. Mocks must be localized in a mocks/ subfolder next to the interface being mocked.
4. Never Use Table-Driven Tests
Avoid table-driven tests. Write explicit test functions for each scenario.
5. Never Mix Positive and Negative Tests
Keep positive (success) and negative (error) test cases in separate test functions.
6. Handle All Errors Explicitly
Never ignore errors. Always handle them explicitly or return them to the caller.
7. Prefer Small, Focused Interfaces
Design interfaces with few methods. Use composition over large interfaces.
8. Use any Instead of interface{}
For generic types, prefer any over interface{} (Go 1.18+).
Standard Go Directory Structure
project-root/
├── cmd/ # Main applications
│ └── myapp/
│ └── main.go
├── internal/ # Private application code
│ ├── handler/ # HTTP handlers
│ │ ├── handler.go
│ │ ├── handler_test.go
│ │ └── mocks/ # Mocks for handler interfaces
│ ├── service/ # Business logic
│ │ ├── service.go
│ │ ├── service_test.go
│ │ └── mocks/
│ └── repository/ # Data access
│ ├── repository.go
│ ├── repository_test.go
│ └── mocks/
├── pkg/ # Public library code
│ └── client/
│ ├── client.go
│ ├── client_test.go
│ └── mocks/
├── api/ # API definitions (OpenAPI, protobuf)
├── configs/ # Configuration files
├── go.mod
├── go.sum
└── README.md
Quick Reference
Common Test Patterns
// Unit test with mock
func TestServiceCreate(t *testing.T) {
mockRepo := mocks.NewRepository(t)
mockRepo.On("Save", mock.Anything).Return(nil)
svc := NewService(mockRepo)
err := svc.Create(context.Background(), data)
require.NoError(t, err)
mockRepo.AssertExpectations(t)
}
// Separate negative test
func TestServiceCreate_RepoError(t *testing.T) {
mockRepo := mocks.NewRepository(t)
mockRepo.On("Save", mock.Anything).Return(errors.New("db error"))
svc := NewService(mockRepo)
err := svc.Create(context.Background(), data)
require.Error(t, err)
require.Contains(t, err.Error(), "db error")
}
Naming Conventions
- Packages: Short, lowercase, no underscores (
handler,service) - Files: Lowercase with underscores (
user_service.go,user_service_test.go) - Types: PascalCase (
UserService,HTTPHandler) - Functions/Methods: PascalCase for exported, camelCase for unexported
- Interfaces: Often end with
-ersuffix (Reader,Writer,UserRepository)
Navigation Table
Use this table to find detailed guidance for specific tasks:
| If You Need To... | See This Resource |
|---|---|
| Set up a new Go project structure | Project Structure |
| Understand Go naming conventions | Naming Conventions |
| Write tests with TDD, testify/require, and mockery | Testing Guide |
| Organize packages, interfaces, and dependencies | Code Organization |
| Handle errors idiomatically | Error Handling |
| Work with goroutines, channels, and context | Concurrency Patterns |
| Manage dependencies and go.mod | Dependencies |
| See complete working examples | Complete Examples |
Resources
This skill includes detailed reference documentation in the references/ directory. Claude will load these resources as needed when working on specific tasks.
You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
rust-coding-skill
UtakataKyosui
Guides Claude in writing idiomatic, efficient, well-structured Rust code using proper data modeling, traits, impl organization, macros, and build-speed best practices.
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.