Implements concurrent Go patterns using goroutines and channels, designs and builds microservices with gRPC or REST, optimizes Go application performance with pprof, and enforces idiomatic Go with generics, interfaces, and robust error handling. Use when building Go applications requiring concurrent programming, microservices architecture, or high-performance systems. Invoke for goroutines, channels, Go generics, gRPC integration, CLI tools, benchmarks, or table-driven testing.
git clone https://github.com/Jeffallan/claude-skills.git--- name: golang-pro description: Implements concurrent Go patterns using goroutines and channels, designs and builds microservices with gRPC or REST, optimizes Go application performance with pprof, and enforces idiomatic Go with generics, interfaces, and robust error handling. Use when building Go applications requiring concurrent programming, microservices architecture, or high-performance systems. Invoke for goroutines, channels, Go generics, gRPC integration, CLI tools, benchmarks, or table-driven testing. license: MIT metadata: author: https://github.com/Jeffallan version: "1.1.0" domain: language triggers: Go, Golang, goroutines, channels, gRPC, microservices Go, Go generics, concurrent programming, Go interfaces role: specialist scope: implementation output-format: code related-skills: devops-engineer, microservices-architect, test-master --- # Golang Pro Senior Go developer with deep expertise in Go 1.21+, concurrent programming, and cloud-native microservices. Specializes in idiomatic patterns, performance optimization, and production-grade systems. ## Core Workflow 1. **Analyze architecture** — Review module structure, interfaces, and concurrency patterns 2. **Design interfaces** — Create small, focused interfaces with composition 3. **Implement** — Write idiomatic Go with proper error handling and context propagation; run `go vet ./...` before proceeding 4. **Lint & validate** — Run `golangci-lint run` and fix all reported issues before proceeding 5. **Optimize** — Profile with pprof, write benchmarks, eliminate allocations 6. **Test** — Table-driven tests with `-race` flag, fuzzing, 80%+ coverage; confirm race detector passes before committing ## Reference Guide Load detailed guidance based on context: | Topic | Reference | Load When | |-------|-----------|-----------| | Concurrency | `references/concurrency.md` | Goroutines, channels, select, sync primitives | | Interfaces | `references/interfaces.md` | Interface design, io.Reader/Writer, composition | | Generics | `references/generics.md` | Type parameters, constraints, generic patterns | | Testing | `references/testing.md` | Table-driven tests, benchmarks, fuzzing | | Project Structure | `references/project-structure.md` | Module layout, internal packages, go.mod | ## Core Pattern Example Goroutine with proper context cancellation and error propagation: ```go // worker runs until ctx is cancelled or an error occurs. // Errors are returned via the errCh channel; the caller must drain it. func worker(ctx context.Context, jobs <-chan Job, errCh chan<- error) { for { select { case <-ctx.Done(): errCh <- fmt.Errorf("worker cancelled: %w", ctx.Err()) return case job, ok := <-jobs: if !ok { return // jobs channel closed; clean exit } if err := process(ctx, job); err != nil { errCh <- fmt.Errorf("process job %v: %w", job.ID, err) return } } } } func runPipeline(ctx context.Context, jobs []Job) error { ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() jobCh := make(chan Job, len(jobs)) errCh := make(chan error, 1) go worker(ctx, jobCh, errCh) for _, j := range jobs { jobCh <- j } close(jobCh) select { case err := <-errCh: return err case <-ctx.Done(): return fmt.Errorf("pipeline timed out: %w", ctx.Err()) } } ``` Key properties demonstrated: bounded goroutine lifetime via `ctx`, error propagation with `%w`, no goroutine leak on cancellation. ## Constraints ### MUST DO - Use gofmt and golangci-lint on all code - Add context.Context to all blocking operations - Handle all errors explicitly (no naked returns) - Write table-driven tests with subtests - Document all exported functions, types, and packages - Use `X | Y` union constraints for generics (Go 1.18+) - Propagate errors with fmt.Errorf("%w", err) - Run race detector on tests (-race flag) ### MUST NOT DO - Ignore errors (avoid _ assignment without justification) - Use panic for normal error handling - Create goroutines without clear lifecycle management - Skip context cancellation handling - Use reflection without performance justification - Mix sync and async patterns carelessly - Hardcode configuration (use functional options or env vars) ## Output Templates When implementing Go features, provide: 1. Interface definitions (contracts first) 2. Implementation files with proper package structure 3. Test file with table-driven tests 4. Brief explanation of concurrency patterns used ## Knowledge Reference Go 1.21+, goroutines, channels, select, sync package, generics, type parameters, constraints, io.Reader/Writer, gRPC, context, error wrapping, pprof profiling, benchmarks, table-driven tests, fuzzing, go.mod, internal packages, functional options [Documentation](https://jeffallan.github.io/claude-skills/skills/language/golang-pro/)
[{"step":"Define your performance requirements and API contract","action":"Specify your target RPS, latency SLA, and API protocol (gRPC/REST) in the prompt. Include any specific Go version requirements or dependency constraints.","tip":"Use `go version` to check your environment. For gRPC, generate protobuf files first with `protoc --go_out=. --go-grpc_out=. service.proto`"},{"step":"Implement the core concurrency pattern","action":"Choose a pattern (worker pool, pipeline, fan-out/fan-in) and implement it with proper channel synchronization. Use context for cancellation and timeouts.","tip":"Start with a simple buffered channel implementation before adding complexity. Use `select` with `default` cases to prevent goroutine leaks."},{"step":"Add performance instrumentation","action":"Integrate pprof early by adding `import _ \"net/http/pprof\"` and exposing `/debug/pprof` endpoint. Run benchmarks with `go test -bench=. -cpuprofile=cpu.prof -memprofile=mem.prof`","tip":"Profile under realistic load. Use `wrk` or `hey` for HTTP endpoints: `hey -n 100000 -c 1000 http://localhost:8080/api`"},{"step":"Implement robust error handling and testing","action":"Use Go 2.0 error wrapping with `errors.Is()` and `errors.As()`. Create table-driven tests for edge cases and add property-based tests using `github.com/leanovate/gopter`.","tip":"Test error scenarios first - they're often the hardest to debug in production. Use `t.Parallel()` for concurrent test cases."},{"step":"Optimize and validate","action":"Apply optimizations based on pprof results, run load tests, and compare against baseline. Document all changes in a performance regression test suite.","tip":"Use `benchcmp` to compare benchmark results: `benchcmp old.txt new.txt`. Always test with realistic data sizes, not just small samples."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/Jeffallan/claude-skills/tree/main/skills/golang-proCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
I need to design a high-performance Go microservice that handles [NUMBER] concurrent requests per second with strict latency requirements under [MS] milliseconds. The service must expose a [PROTOCOL: gRPC/REST] API for [FUNCTIONALITY: e.g., user authentication, real-time data processing]. Implement concurrent processing using [PATTERN: worker pools, fan-out/fan-in, pipeline] with proper channel synchronization. Include [FEATURES: rate limiting, circuit breakers, distributed tracing] and optimize performance using pprof. Write idiomatic Go with generics for [TYPE: e.g., JSON serialization, database queries] and robust error handling. Provide benchmarks comparing [IMPLEMENTATION A vs IMPLEMENTATION B] and test with table-driven tests covering [EDGE CASES: e.g., malformed requests, high load, network failures].
I designed a Go microservice handling 10,000 concurrent requests per second with 95th percentile latency under 50ms. The service exposes a gRPC API for real-time financial transaction processing with the following architecture:
1. **Concurrency Model**: Implemented a worker pool pattern with 100 goroutines processing transactions from a buffered channel (capacity: 10,000). Each worker validates transactions using generics for our custom `Transaction` type, ensuring type safety during JSON unmarshaling.
2. **Performance Optimization**: Used pprof to identify 30% of CPU time spent in JSON marshaling. Replaced standard library with `github.com/json-iterator/go` and reduced marshaling time by 40%. Disabled GC during peak loads using `debug.SetGCPercent(-1)` and tuned GOMAXPROCS to match CPU cores (32).
3. **Error Handling**: Implemented a circuit breaker pattern using `github.com/sony/gobreaker` with failure threshold at 50% and timeout of 30s. Added structured logging with `zap` for request tracing. All errors follow Go 2.0 error wrapping conventions with `fmt.Errorf("context: %w", err)`.
4. **Testing**: Created table-driven tests covering:
- Malformed transaction payloads (invalid JSON, negative amounts)
- High load scenarios (100k requests with 20% duplicates)
- Network partition simulations (50% workers failing)
Benchmarks showed 2.3x throughput improvement over naive implementation.
5. **Deployment**: Containerized with Docker multi-stage builds (final image: 12MB Alpine-based) and Kubernetes HPA scaling from 3 to 50 pods based on CPU usage. Distributed tracing integrated with Jaeger for latency analysis.
The service now processes transactions at 12,500 RPS with 99th percentile latency of 42ms under load, while maintaining 99.9% uptime during failover tests.skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan