golang-pro

Implements idiomatic Go code with concurrency, generics, error handling, and table-driven tests.

Updated Nov 1, 2024
One-click install
npx skills add https://github.com/mlorentedev/dotfiles --skill golang-pro-mlorentedev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-pro
Source: https://github.com/mlorentedev/dotfiles/tree/main/harness/skills/golang-pro
Command: npx skills add https://github.com/mlorentedev/dotfiles --skill golang-pro-mlorentedev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing production-grade Go requires consistent application of concurrency patterns, error propagation, interface design, and testing discipline. This Skill guides the AI to produce idiomatic Go 1.21+ code that follows these standards instead of ad-hoc implementations. ## Core Features & Use Cases - Concurrency Patterns: Implements goroutines with context cancellation, channels, select statements, and error propagation without goroutine leaks. - Microservices & APIs: Designs small composable interfaces and builds gRPC/REST services with proper context propagation. - Testing & Performance: Writes table-driven tests with the race detector, fuzzing, benchmarks, and pprof profiling. - Use Case: Ask the AI to build a worker pipeline that processes jobs concurrently; it returns interface definitions, an implementation with context-based cancellation, and table-driven tests verified with go vet, golangci-lint, and -race. ## Quick Start Ask the AI to implement a concurrent job-processing pipeline in Go with context cancellation, error wrapping, and table-driven tests.

Frequently Asked Questions about golang-pro

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write concurrent Go code with goroutines and channels?

Use goroutines with context.Context for cancellation, channels for job distribution, and select for multiplexing. Propagate errors through a dedicated error channel with fmt.Errorf and %w wrapping, and always close channels to signal clean worker exits.

How to write table-driven tests in Go?

Define a slice of anonymous structs holding inputs and expected outputs, then loop over them with t.Run for subtests. Run tests with the -race flag to detect data races, and add fuzzing and benchmarks for critical paths.

Does Go generics support union type constraints?

Yes, Go 1.18+ supports union constraints using the X | Y syntax in type parameter lists. This lets generic functions accept any of several specified types while keeping compile-time type safety.

How do I prevent goroutine leaks in Go?

Give every goroutine a bounded lifetime using context cancellation or closed channels, and ensure the caller drains error channels. Avoid launching goroutines without a clear exit condition or lifecycle owner.

When should I avoid using reflection in Go?

Avoid reflection unless there is a measurable performance justification, since it bypasses compile-time type checking and adds runtime overhead. Prefer generics or small interfaces for type-flexible designs.