Use when adding new error messages to React, or seeing "unknown error code" warnings.
npx skills add mOdrA40/claude-codex-skills-directory --skill "golang-senior-lead"
Install specific skill from multi-skill repository
# Description
Expert Golang senior/lead developer dengan 20+ tahun pengalaman. Gunakan skill ini ketika bekerja dengan Go/Golang projects untuk membuat kode clean, maintainable, scalable, struktur folder production-grade, Docker containerization, debugging, mendeteksi celah crash/bug/race condition, code review standar senior engineer, testing strategies, performance optimization, dan library selection battle-tested. Trigger keywords include golang, go, docker, microservice, api, backend, clean code, refactor, debugging.
# SKILL.md
name: golang-senior-lead
description: "Expert Golang senior/lead developer dengan 20+ tahun pengalaman. Gunakan skill ini ketika bekerja dengan Go/Golang projects untuk membuat kode clean, maintainable, scalable, struktur folder production-grade, Docker containerization, debugging, mendeteksi celah crash/bug/race condition, code review standar senior engineer, testing strategies, performance optimization, dan library selection battle-tested. Trigger keywords include golang, go, docker, microservice, api, backend, clean code, refactor, debugging."
Golang Senior/Lead Developer Expertise
Skill ini mengandung accumulated wisdom dari 20+ tahun production experience. Setiap recommendation sudah battle-tested di high-traffic systems.
Core Philosophy
KISS (Keep It Stupid Simple) - Kode terbaik adalah kode yang tidak perlu ditulis. Setiap line of code adalah liability.
Less is More - Jangan over-engineer. Solve today's problem, not imaginary future problems. YAGNI (You Ain't Gonna Need It).
Explicit over Implicit - Go menghargai explicitness. Jangan gunakan magic. Kode harus readable tanpa documentation.
Fail Fast, Fail Loud - Error harus di-handle segera, jangan di-ignore. Panic early jika state tidak valid.
Project Structure (Production-Grade)
project-name/
βββ cmd/ # Entry points (main packages)
β βββ api/
β β βββ main.go # HTTP API server
β βββ worker/
β βββ main.go # Background worker
βββ internal/ # Private packages (tidak bisa di-import external)
β βββ domain/ # Business entities & interfaces (CORE)
β β βββ user.go # Entity + Repository interface
β β βββ order.go
β βββ usecase/ # Business logic (orchestration)
β β βββ user/
β β βββ service.go
β β βββ service_test.go
β βββ repository/ # Data access implementations
β β βββ postgres/
β β βββ user.go
β βββ handler/ # HTTP/gRPC handlers
β β βββ http/
β β βββ user.go
β βββ pkg/ # Internal shared utilities
β βββ validator/
β βββ logger/
βββ pkg/ # Public packages (bisa di-import external)
βββ config/ # Configuration files
βββ migrations/ # Database migrations
βββ scripts/ # Build/deploy scripts
βββ docker/
β βββ Dockerfile
β βββ docker-compose.yml
βββ go.mod
βββ go.sum
βββ Makefile
βββ .golangci.yml # Linter config
Critical Rules:
- internal/ = private, tidak bisa di-import dari luar module
- domain/ = ZERO dependencies ke infrastructure. Pure business logic.
- Dependency flow: handler β usecase β repository. NEVER backwards.
Error Handling Golden Rules
// β NEVER ignore errors
result, _ := someFunction()
// β
ALWAYS handle or propagate
result, err := someFunction()
if err != nil {
return fmt.Errorf("someFunction failed: %w", err) // wrap with context
}
// β NEVER use panic for expected errors
if user == nil {
panic("user not found") // WRONG!
}
// β
Return error for expected failures
if user == nil {
return nil, ErrUserNotFound
}
// Sentinel errors (define di package level)
var (
ErrNotFound = errors.New("not found")
ErrUnauthorized = errors.New("unauthorized")
)
Concurrency Patterns (Race Condition Prevention)
Lihat references/concurrency.md untuk patterns lengkap.
Quick Rules:
- Selalu gunakan sync.Mutex untuk shared state
- Prefer channels untuk communication, mutex untuk state protection
- SELALU run go test -race ./... sebelum merge
- Gunakan context.Context untuk cancellation propagation
Docker Best Practices
Lihat references/docker.md untuk Dockerfile dan docker-compose templates.
Quick Rules:
- Multi-stage builds untuk minimal image size
- Non-root user untuk security
- .dockerignore wajib
- Health checks wajib untuk orchestration
- Pin specific versions, NEVER use latest
Recommended Libraries (Battle-Tested)
Lihat references/libraries.md untuk complete list dengan use cases.
Essential Stack:
| Category | Library | Reason |
|----------|---------|--------|
| HTTP Router | chi atau gin | Chi lebih Go-idiomatic, Gin lebih feature-rich |
| Database | sqlx + pgx | Raw SQL power + type safety |
| Validation | validator/v10 | De-facto standard |
| Config | viper atau envconfig | Viper untuk complex, envconfig untuk simple |
| Logging | zerolog atau zap | Structured, fast, production-ready |
| Testing | testify + testcontainers | Assertions + integration tests |
Debugging Workflow
Lihat references/debugging.md untuk advanced techniques.
Quick Commands:
# Race detector
go test -race ./...
# CPU profiling
go test -cpuprofile cpu.prof -bench .
# Memory profiling
go test -memprofile mem.prof -bench .
# Deadlock detection
GODEBUG=schedtrace=1000 ./app
# Detailed stack traces
GOTRACEBACK=all ./app
Code Review Checklist
Sebelum approve PR, pastikan:
- Error Handling - Semua error di-handle, tidak ada
_untuk error - Race Conditions - Shared state dilindungi,
go test -racepass - Resource Leaks - Semua
defer Close()ada, context digunakan - Tests - Unit tests ada, edge cases covered
- Naming - Clear, Go conventions (MixedCaps, not snake_case)
- Simplicity - Tidak over-engineered, KISS principle
Testing Strategy
// Table-driven tests (Go idiom)
func TestCalculatePrice(t *testing.T) {
tests := []struct {
name string
input float64
expected float64
wantErr bool
}{
{"normal price", 100, 110, false},
{"zero price", 0, 0, false},
{"negative price", -1, 0, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := CalculatePrice(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
}
if got != tt.expected {
t.Errorf("got %v, want %v", got, tt.expected)
}
})
}
}
Performance Quick Wins
- Preallocate slices -
make([]T, 0, expectedSize) - Avoid string concatenation in loops - Use
strings.Builder - Sync.Pool untuk frequent allocations
- Buffer channels - Prevent goroutine blocking
- Index database queries - Explain analyze sebelum deploy
Common Pitfalls to Avoid
| Pitfall | Consequence | Prevention |
|---|---|---|
| Nil pointer dereference | Panic crash | Always check nil before access |
| Goroutine leak | Memory leak | Use context for cancellation |
| Closing nil channel | Panic | Check before close |
| Data race | Undefined behavior | go test -race |
| Slice append gotcha | Data corruption | Copy when needed |
Additional References
- references/concurrency.md - Concurrency patterns lengkap
- references/docker.md - Docker templates dan best practices
- references/libraries.md - Complete library recommendations
- references/debugging.md - Advanced debugging techniques
- references/patterns.md - Design patterns untuk Go
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.