go-dev
General Go development guide. Use when writing Go code, implementing best practices, formatting code, writing tests, using mocks, handling errors, or understanding Go coding conventions. Covers code style, testing patterns, dependency injection, interface design, and performance optimization. Project-agnostic guidelines applicable to any Go codebase.
When & Why to Use This Skill
The Go Development Guide skill is a comprehensive resource for software engineers designed to enforce idiomatic Go (Golang) standards and architectural best practices. It provides actionable guidance on writing clean, maintainable code through dependency injection, interface-based design, and robust testing patterns, ensuring that Go projects are scalable and performant from the ground up.
Use Cases
- Code Standardization: Establishing consistent coding styles, formatting rules, and naming conventions across diverse Go projects and engineering teams.
- Architecting Testable Systems: Implementing dependency injection and interface verification to facilitate seamless mocking and achieve high test coverage.
- Advanced Testing Implementation: Developing rigorous table-driven tests and utilizing automated mock generation with tools like mockery for reliable QA.
- Performance & Safety Optimization: Applying pre-allocation strategies for collections and adopting optional types for safer nil handling in production environments.
| name | go-dev |
|---|---|
| description | General Go development guide. Use when writing Go code, implementing best practices, formatting code, writing tests, using mocks, handling errors, or understanding Go coding conventions. Covers code style, testing patterns, dependency injection, interface design, and performance optimization. Project-agnostic guidelines applicable to any Go codebase. |
Go Development Guide
General-purpose Go development guidelines and best practices.
Core Principles
- Write effective Go code (see
effective-goskill for reference) - Use the Go standard library whenever possible
- Limit line length to 120 characters
- Write testable code using interfaces and dependency injection
- Wrap OS operations in interfaces for mockability
Code Organization
- Add interface verification after struct definitions:
var _ Interface = (*Struct)(nil) - Provide
NewStructNameconstructors for all structs - Always use dependency injection in constructors
- Pre-allocate collections when size is known
Optional Types
Use samber/mo for safer nil handling:
import "github.com/samber/mo"
type Config struct {
Shell mo.Option[string]
}
if shell, ok := config.Shell.Get(); ok {
// use shell
}
Testing
- Use
testifylibrary withrequirefor assertions - Name tests descriptively:
Test_<DescriptiveStatement> - Use table-driven tests for multiple scenarios
- Generate mocks with
mockery(moq template) - never edit manually - Check errors by keywords, not full message matching
Detailed References
For all coding conventions and patterns: See Code Style Reference
For all testing conventions: See Test Style Reference