About writing-go
writing-go is a skill reference for Go developers, outlining principles such as using the standard library first, composition, and contextual errors. It provides code patterns, Go 1.25 notes, tooling guidance, and common pitfalls.
Key features
- 01Error handling with contextual wrapping
- 02Options pattern and table-driven test examples
- 03Overview of Go 1.25 features
- 04Build, test, and lint tools
- 05Concurrency and standard-library pitfalls
Use cases
- 01Define development conventions for a Go project
- 02Design error handling for functions and services
- 03Write table-driven tests and review concurrency code
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ julianobarbosa/ claude-code-skills --skill writing-goAfter installing, type/writing-goin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
CLI.mdPATTERNS.mdTESTING.mdDetails
From the project READMEGo 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
Gotchas
nilchannel sends/receives block forever; closed channel receives return zero value immediately —selectwith a nil channel case disables that case, useful pattern but easy to do accidentally.defercaptures arguments at the call site, not at execution —defer fmt.Println(time.Now())captures NOW, not the deferred time.- Pre-Go 1.22 for-loop variable capture closures over ONE variable across all iterations — the goroutine-in-loop bug. Go 1.22 changed semantics; old habits create subtle bugs in mixed-version code.
errors.IswalksUnwrap()chains, BUT if a wrapped error implementsIs(target error) boolitself, that custom Is wins over walking — confusing when migrating from xerrors.sync.Poolitems can be GC'd betweenGetand the nextPut— never rely on a Pool to retain state.
Comments
Markdown supported