go-development
Skill2 starsChanged 4 months agoMITView on GitHub
Go (Golang) best practices, patterns, and idioms for building reliable, performant applications. Use when the task involves `Go project`, `Golang`, `go.mod`, `goroutines`, or `Go error handling`.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- ibarryyan/skills-runtimetheir own version, first seen Oct 3, 2026
- netresearch/go-development-skilltheir own version, first seen Sep 30, 2026
- codetesla51/skillstheir own version, first seen Sep 25, 2026
- ProjAnvil/MindForgetheir own version, first seen Mar 5, 2026
- carloss765/agent-skillstheir own version, first seen Jan 15, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- netresearch/go-development-skill★ 12same name
- ProjAnvil/MindForge★ 3same name
- carloss765/agent-skills★ 1same name
- codetesla51/skills★ 1same name
- ibarryyan/skills-runtime★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository43 other files it gives its agents.
- accessibilitySkill
- best-practicesSkill
- brainstormingSkill
- core-web-vitalsSkill
- cypress-e2eSkill
- docker-expertSkill
- drizzle-ormSkill
- elixir-developmentSkill
- eslint-configSkill
- express-apiSkill
- frontend-designSkill
- github-actionsSkill
- grafana-dashboardsSkill
- grpc-apiSkill
- helm-chartsSkill
- jest-testingSkill
- kubernetes-orchestrationSkill
- makefileSkill
- markdown-a11ySkill
- nothing-designSkill
- performanceSkill
- php-developmentSkill
- pinned-tagSkill
- postgresql-developmentSkill
- pr-creatorSkill
- prettier-formattingSkill
- pydanticSkill
- qwik-developmentSkill
- rails-developmentSkill
- ruby-developmentSkill
- rust-async-patternsSkill
- seoSkill
- skill-creatorSkill
- solidjs-developmentSkill
- sqlalchemySkill
- sql-optimization-patternsSkill
- swift-ios-developmentSkill
- tensorflow-mlSkill
- testing-librarySkill
- trpc-type-safetySkill
- webapp-testingSkill
- web-quality-auditSkill
- zig-developmentSkill
The file
Files
Go Development
Production patterns and idioms for Go programming, covering project structure, error handling, concurrency, interfaces, testing, and module management.
When to Use This Skill
- Starting or structuring a Go project
- Writing idiomatic Go error handling
- Working with goroutines and channels
- Designing interfaces and composable packages
- Writing tests with
go test - Managing dependencies with Go modules
- Using context for cancellation and propagation
Core Concepts
1. Project Layout
myapp/
├── cmd/
│ └── myapp/
│ └── main.go # Entry point
├── internal/ # Private packages (not importable externally)
│ ├── handler/
│ │ └── handler.go
│ ├── service/
│ │ └── service.go
│ └── repository/
│ └── repository.go
├── pkg/ # Public reusable packages
│ └── httputil/
│ └── response.go
├── go.mod
├── go.sum
├── Makefile
└── README.md2. Key Principles
| Principle | Go Idiom |
| Error handling | Return error as last value, check immediately |
| Composition | Embed interfaces, not structs |
| Concurrency | Share memory by communicating (channels) |
| Simplicity | Fewer abstractions, explicit over implicit |
| Zero values | Design types so zero value is useful |
Quick Start
# Initialize a new module
go mod init github.com/user/myapp
# Add dependencies
go get github.com/gin-gonic/gin@latest
# Tidy dependencies
go mod tidy
# Build and run
go build -o myapp ./cmd/myapp
go run ./cmd/myapp
# Run tests
go test ./...
go test -v -race -count=1 ./...Patterns
Pattern 1: Error Handling
package service
import (
"errors"
"fmt"
)
// Define sentinel errors for comparison
var (
ErrNotFound = errors.New("not found")
ErrUnauthorized = errors.New("unauthorized")
)
// Custom error type with context
type ValidationError struct {
Field string
Message string
}
func (e *ValidationError) Error() string {
return fmt.Sprintf("validation failed on %s: %s", e.Field, e.Message)
}
// Wrap errors with context using %w
func GetUser(id string) (*User, error) {
user, err := db.Find(id)
if err != nil {
return nil, fmt.Errorf("GetUser(%s): %w", id, err)
}
if user == nil {
return nil, fmt.Errorf("GetUser(%s): %w", id, ErrNotFound)
}
return user, nil
}
// Check wrapped errors with errors.Is and errors.As
func HandleRequest(id string) error {
user, err := GetUser(id)
if err != nil {
if errors.Is(err, ErrNotFound) {
return writeNotFound()
}
var validErr *ValidationError
if errors.As(err, &validErr) {
return writeBadRequest(validErr.Field, validErr.Message)
}
return fmt.Errorf("handling request: %w", err)
}
return writeJSON(user)
}Pattern 2: Goroutines and Channels
package worker
import (
"context"
"fmt"
"sync"
)
// Fan-out/fan-in with worker pool
func ProcessItems(ctx context.Context, items []string, workers int) []Result {
jobs := make(chan string, len(items))
results := make(chan Result, len(items))
// Start workers
var wg sync.WaitGroup
for i := 0; i < workers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for item := range jobs {
select {
case <-ctx.Done():
return
default:
results <- process(item)
}
}
}()
}
// Send jobs
for _, item := range items {
jobs <- item
}
close(jobs)
// Wait and close results
go func() {
wg.Wait()
close(results)
}()
// Collect results
var out []Result
for r := range results {
out = append(out, r)
}
return out
}
// Select for timeout and cancellation
func FetchWithTimeout(ctx context.Context, url string) (string, error) {
ch := make(chan string, 1)
errCh := make(chan error, 1)
go func() {
data, err := httpGet(url)
if err != nil {
errCh <- err
return
}
ch <- data
}()
select {
case data := <-ch:
return data, nil
case err := <-errCh:
return "", err
case <-ctx.Done():
return "", fmt.Errorf("fetch %s: %w", url, ctx.Err())
}
}Pattern 3: Interfaces and Composition
package service
import "context"
// Small, focused interfaces (accept interfaces, return structs)
type UserReader interface {
GetUser(ctx context.Context, id string) (*User, error)
}
type UserWriter interface {
SaveUser(ctx context.Context, user *User) error
DeleteUser(ctx context.Context, id string) error
}
// Compose interfaces
type UserRepository interface {
UserReader
UserWriter
}
// Depend on the smallest interface needed
type UserService struct {
reader UserReader // Only needs read access
}
func NewUserService(reader UserReader) *UserService {
return &UserService{reader: reader}
}
func (s *UserService) GetProfile(ctx context.Context, id string) (*Profile, error) {
user, err := s.reader.GetUser(ctx, id)
if err != nil {
return nil, fmt.Errorf("getting profile: %w", err)
}
return toProfile(user), nil
}Pattern 4: Context Propagation
package middleware
import (
"context"
"net/http"
)
type contextKey string
const userIDKey contextKey = "userID"
// Store values in context
func AuthMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
userID, err := validateToken(r.Header.Get("Authorization"))
if err != nil {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
ctx := context.WithValue(r.Context(), userIDKey, userID)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
// Retrieve values from context
func UserIDFromContext(ctx context.Context) (string, bool) {
id, ok := ctx.Value(userIDKey).(string)
return id, ok
}
// Pass context through the call chain — always first parameter
func (s *Service) DoWork(ctx context.Context, input Input) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
return s.repo.Save(ctx, input)
}Pattern 5: Testing
package service_test
import (
"context"
"errors"
"testing"
"github.com/user/myapp/internal/service"
)
// Table-driven tests
func TestGetProfile(t *testing.T) {
tests := []struct {
name string
userID string
mock *mockReader
want *service.Profile
wantErr error
}{
{
name: "success",
userID: "123",
mock: &mockReader{user: &service.User{ID: "123", Name: "Alice"}},
want: &service.Profile{ID: "123", DisplayName: "Alice"},
},
{
name: "not found",
userID: "999",
mock: &mockReader{err: service.ErrNotFound},
wantErr: service.ErrNotFound,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
svc := service.NewUserService(tt.mock)
got, err := svc.GetProfile(context.Background(), tt.userID)
if tt.wantErr != nil {
if !errors.Is(err, tt.wantErr) {
t.Errorf("want error %v, got %v", tt.wantErr, err)
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got.ID != tt.want.ID {
t.Errorf("want ID %s, got %s", tt.want.ID, got.ID)
}
})
}
}
// Mock by implementing the interface
type mockReader struct {
user *service.User
err error
}
func (m *mockReader) GetUser(_ context.Context, _ string) (*service.User, error) {
return m.user, m.err
}
// Test helpers
func TestMain(m *testing.M) {
// Setup/teardown for entire package
os.Exit(m.Run())
}Pattern 6: Defer, Panic, Recover
package resource
import (
"fmt"
"io"
"os"
)
// Defer for cleanup — executes LIFO on function exit
func ReadFile(path string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("opening %s: %w", path, err)
}
defer f.Close()
return io.ReadAll(f)
}
// Capture close errors with named returns
func WriteFile(path string, data []byte) (err error) {
f, err := os.Create(path)
if err != nil {
return fmt.Errorf("creating %s: %w", path, err)
}
defer func() {
if cerr := f.Close(); cerr != nil && err == nil {
err = fmt.Errorf("closing %s: %w", path, cerr)
}
}()
_, err = f.Write(data)
return err
}
// Recover from panics at API boundaries only
func SafeHandler(fn func()) {
defer func() {
if r := recover(); r != nil {
fmt.Printf("recovered from panic: %v\n", r)
}
}()
fn()
}Best Practices
Do's
- Return errors — Check every error immediately after the call
- Use
fmt.Errorfwith%w— For wrapping errors with context - Accept interfaces, return structs — Keeps APIs flexible
- Use
context.Context— As first parameter for cancellation and deadlines - Write table-driven tests — Cover edge cases systematically
- Use
sync.WaitGroup— To coordinate goroutine completion - Prefer
makeandlen— Over manual capacity management - Run
go vetandstaticcheck— Catch bugs before runtime
Don'ts
- Don't ignore errors —
_ = doSomething()hides bugs - Don't use
panicfor control flow — Reserve for truly unrecoverable states - Don't overuse
interface{}/any— Use generics (Go 1.18+) or typed interfaces - Don't leak goroutines — Always provide a way to stop (context, done channel)
- Don't use
init()heavily — Makes testing and reasoning harder - Don't embed mutexes in exported structs — Keep synchronization internal
Resources
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

