/programming-skills:golang-dev-guidelinesfrom programming-skills
Use these guidelines when writing, reviewing, or refactoring Go code
Claude never picks this skill on its own
Claude Code cannot parse its frontmatter, so it ignores every field there: the description on this page is for you to read, but Claude never sees it. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /programming-skills:golang-dev-guidelines still runs it.
What the skill costs in Claude's context, stage by stage
No description Claude Code can read, so Claude's list leaves it out: only you can start it.
SKILL.md joins the conversation and stays.
Use these guidelines when writing, reviewing, or refactoring Go code to ensure idiomatic, maintainable, and high-quality code.
These proverbs from Rob Pike capture the philosophy of Go programming:
Don't communicate by sharing memory, share memory by communicating - Use channels to pass data between goroutines instead of shared variables with locks.
Concurrency is not parallelism - Concurrency is about dealing with many things at once; parallelism is about doing many things at once.
Channels orchestrate; mutexes serialize - Use channels for coordination and communication; use mutexes only when you need to protect shared state.
The bigger the interface, the weaker the abstraction - Prefer small, focused interfaces. The ideal interface has one method.
Make the zero value useful - Design types so their zero value is immediately usable without initialization.
interface{} says nothing - Avoid empty interface when possible; it provides no compile-time type safety.
Gofmt's style is no one's favorite, yet gofmt is everyone's favorite - Always use gofmt. Consistency matters more than personal preference.
A little copying is better than a little dependency - Don't import a large package for a small function. Copy small amounts of code when appropriate.
Syscall must always be guarded with build tags - Platform-specific code should be properly isolated.
Cgo must always be guarded with build tags - CGo code should be isolated and marked appropriately.
Cgo is not Go - Avoid CGo when possible; it complicates builds and reduces portability.
With the unsafe package there are no guarantees - Avoid unsafe unless absolutely necessary; it bypasses Go's type safety.
Clear is better than clever - Write straightforward code. Readability trumps cleverness.
Reflection is never clear - Avoid reflection when possible; it makes code harder to understand and maintain.
Errors are values - Errors are not exceptions. Handle them as regular values in your control flow.
Don't just check errors, handle them gracefully - Provide context when returning errors. Use error wrapping.
Design the architecture, name the components, document the details - Good naming and documentation are part of good design.
Documentation is for users - Write documentation that helps users understand how to use your code.
Don't panic - Reserve panic for truly unrecoverable situations. Return errors instead.
obj.Owner() not obj.GetOwner()Reader,
Writer, FormatterHTTPServer, XMLParser, ID// Good: Add context to errors
if err != nil {
return fmt.Errorf("failed to process user %s: %w", userID, err)
}
// Good: Define sentinel errors for comparison
var ErrNotFound = errors.New("not found")
// Good: Custom error types for rich error information
type ValidationError struct {
Field string
Message string
}
func (e *ValidationError) Error() string {
return fmt.Sprintf("validation failed on %s: %s", e.Field, e.Message)
}
// Good: Use context for cancellation
func process(ctx context.Context, items []Item) error {
for _, item := range items {
select {
case <-ctx.Done():
return ctx.Err()
default:
if err := processItem(item); err != nil {
return err
}
}
}
return nil
}
// Good: Use errgroup for concurrent operations
g, ctx := errgroup.WithContext(ctx)
for _, item := range items {
item := item // capture loop variable
g.Go(func() error {
return processItem(ctx, item)
})
}
if err := g.Wait(); err != nil {
return err
}
// Good: Small, focused interfaces
type Reader interface {
Read(p []byte) (n int, err error)
}
type Writer interface {
Write(p []byte) (n int, err error)
}
// Good: Accept interfaces, return structs
func ProcessData(r io.Reader) (*Result, error) {
// implementation
}
// Good: Make zero value useful
type Buffer struct {
buf []byte
off int
}
// Buffer is usable without explicit initialization
var b Buffer
b.Write([]byte("hello"))
Use the testify/assert package for cleaner, more readable assertions.
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAdd(t *testing.T) {
tests := []struct {
name string
a, b int
expected int
}{
{"positive numbers", 2, 3, 5},
{"negative numbers", -1, -2, -3},
{"mixed numbers", -1, 5, 4},
{"zeros", 0, 0, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := Add(tt.a, tt.b)
assert.Equal(t, tt.expected, result)
})
}
}
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAssertions(t *testing.T) {
// Equality
assert.Equal(t, expected, actual)
assert.NotEqual(t, unexpected, actual)
// Nil checks
assert.Nil(t, err)
assert.NotNil(t, result)
// Boolean
assert.True(t, condition)
assert.False(t, condition)
// Error handling
assert.NoError(t, err)
assert.Error(t, err)
assert.ErrorIs(t, err, ErrNotFound)
assert.ErrorContains(t, err, "not found")
// Collections
assert.Len(t, slice, 3)
assert.Empty(t, slice)
assert.Contains(t, slice, element)
// Use require for fatal assertions (stops test on failure)
require.NoError(t, err) // Test stops here if err != nil
require.NotNil(t, result)
}
TestXxx where Xxx describes what's being testedt.Run("name", ...)BenchmarkXxxExampleXxx (appears in documentation)// Good: Arrange-Act-Assert pattern with assert
func TestUserService_CreateUser(t *testing.T) {
// Arrange
svc := NewUserService(mockDB)
input := &CreateUserInput{Name: "Alice", Email: "[email protected]"}
// Act
user, err := svc.CreateUser(context.Background(), input)
// Assert
require.NoError(t, err)
assert.Equal(t, input.Name, user.Name)
assert.Equal(t, input.Email, user.Email)
assert.NotZero(t, user.ID)
}
func TestWithRequireAndAssert(t *testing.T) {
result, err := DoSomething()
// Use require for errors - no point continuing if this fails
require.NoError(t, err)
require.NotNil(t, result)
// Use assert for checking multiple properties
assert.Equal(t, "expected", result.Name)
assert.True(t, result.IsActive)
assert.Len(t, result.Items, 3)
}
When reviewing Go code, check for:
What SKILL.md sets; muted values are Claude Code's defaults
None: SKILL.md is the whole skill.
npx claudepluginhub mvasilenko/mv-claude-code-marketplace --plugin programming-skillsOther plugins' skills for the same job