Go Development (1.25+)
Core Principles
- Stdlib first: External deps only when justified
- Concrete types: Define interfaces at consumer, return structs
- Composition: Over inheritance, always
- Fail fast: Clear errors with context
- Simple: The obvious solution is usually correct
Quick Patterns
Error Handling
if err := doThing(); err != nil {
return fmt.Errorf("do thing: %w", err)
}
Struct with Options
type Server struct {
addr string
timeout time.Duration
}
func NewServer(addr string, opts ...Option) *Server {
s := &Server{addr: addr, timeout: 30 * time.Second}
for _, opt := range opts {
opt(s)
}
return s
}
Table-Driven Tests
tests := []struct {
name string
input string
want string
wantErr bool
}{
{"valid", "hello", "HELLO", false},
{"empty", "", "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Process(tt.input)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
Go 1.25 Features
- testing/synctest: Deterministic concurrent testing with simulated clock
- encoding/json/v2: Experimental, 3-10x faster (GOEXPERIMENT=jsonv2)
- runtime/trace.FlightRecorder: Production trace capture on-demand
- Container-aware GOMAXPROCS: Auto-detects cgroup limits
- GreenTea GC: Experimental, lower latency (GOEXPERIMENT=greenteagc)
References
- PATTERNS.md - Detailed code patterns
- TESTING.md - Testing strategies with testify/mockery
- CLI.md - CLI application patterns
Tooling
go build ./... # Build
go test -race ./... # Test with race detector
golangci-lint run # Lint
mockery --all # Generate mocks
1---2name: writing-go3description: Idiomatic Go 1.25+ development. Use when writing Go code, designing APIs, discussing Go patterns, or reviewing Go implementations. Emphasizes stdlib, concrete types, simple error handling, and minimal dependencies.4allowed-tools: Read, Bash, Grep, Glob5metadata:6 source: https://skillmd.com/skills/levalencia/writing-go7---89# Go Development (1.25+)1011## Core Principles1213- **Stdlib first**: External deps only when justified14- **Concrete types**: Define interfaces at consumer, return structs15- **Composition**: Over inheritance, always16- **Fail fast**: Clear errors with context17- **Simple**: The obvious solution is usually correct1819## Quick Patterns2021### Error Handling2223```go24if err := doThing(); err != nil {25 return fmt.Errorf("do thing: %w", err)26}27```2829### Struct with Options3031```go32type Server struct {33 addr string34 timeout time.Duration35}3637func NewServer(addr string, opts ...Option) *Server {38 s := &Server{addr: addr, timeout: 30 * time.Second}39 for _, opt := range opts {40 opt(s)41 }42 return s43}44```4546### Table-Driven Tests4748```go49tests := []struct {50 name string51 input string52 want string53 wantErr bool54}{55 {"valid", "hello", "HELLO", false},56 {"empty", "", "", true},57}58for _, tt := range tests {59 t.Run(tt.name, func(t *testing.T) {60 got, err := Process(tt.input)61 if tt.wantErr {62 require.Error(t, err)63 return64 }65 require.NoError(t, err)66 assert.Equal(t, tt.want, got)67 })68}69```7071## Go 1.25 Features7273- **testing/synctest**: Deterministic concurrent testing with simulated clock74- **encoding/json/v2**: Experimental, 3-10x faster (GOEXPERIMENT=jsonv2)75- **runtime/trace.FlightRecorder**: Production trace capture on-demand76- **Container-aware GOMAXPROCS**: Auto-detects cgroup limits77- **GreenTea GC**: Experimental, lower latency (GOEXPERIMENT=greenteagc)7879## References8081- [PATTERNS.md](PATTERNS.md) - Detailed code patterns82- [TESTING.md](TESTING.md) - Testing strategies with testify/mockery83- [CLI.md](CLI.md) - CLI application patterns8485## Tooling8687```bash88go build ./... # Build89go test -race ./... # Test with race detector90golangci-lint run # Lint91mockery --all # Generate mocks92```