Learn idiomatic Go patterns and best practices for robust, maintainable applications.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "golang-patterns" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/golang-patterns/SKILL.md 2. Save it as ~/.claude/skills/golang-patterns/SKILL.md 3. Reload skills and tell me it's ready
Design an idiomatic Go concurrent task processor example with a worker pool, context cancellation, error propagation, and graceful shutdown. Explain why this design is recommended.
Idiomatic Go sample code for concurrency, plus explanations of the key design choices.
Here is my current Go project structure and some code. Suggest a clearer package layout, naming conventions, interface boundaries, and error handling strategy based on common Go conventions.
Refactoring recommendations for structure, naming, and module boundaries, with example layout and code changes.
Review this Go code and identify non-idiomatic parts, including naming, error handling, slice and map usage, interface design, and performance issues. Provide an improved version.
A code review with a list of issues and an improved version aligned with Go idioms.
Idiomatic Go patterns and best practices for building robust, efficient, and maintainable applications.
Go favors simplicity over cleverness. Code should be obvious and easy to read.
// Good: Clear and direct
func GetUser(id string) (*User, error) {
user, err := db.FindUser(id)
if err != nil {
return nil, fmt.Errorf("get user %s: %w", id, err)
}
return user, nil
}
// Bad: Overly clever
func GetUser(id string) (*User, error) {
return func() (*User, error) {
if u, e := db.FindUser(id); e == nil {
return u, nil
} else {
return nil, e
}
}()
}
Design types so their zero value is immediately usable without initialization.
// Good: Zero value is useful
type Counter struct {
mu sync.Mutex
count int // zero value is 0, ready to use
}
func (c *Counter) Inc() {
c.mu.Lock()
c.count++
c.mu.Unlock()
}
// Good: bytes.Buffer works with zero value
var buf bytes.Buffer
buf.WriteString("hello")
// Bad: Requires initialization
type BadCounter struct {
counts map[string]int // nil map will panic
}
Functions should accept interface parameters and return concrete types.
// Good: Accepts interface, returns concrete type
func ProcessData(r io.Reader) (*Result, error) {
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
return &Result{Data: data}, nil
}
// Bad: Returns interface (hides implementation details unnecessarily)
func ProcessData(r io.Reader) (io.Reader, error) {
// ...
}
// Good: Wrap errors with context
func LoadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("load config %s: %w", path, err)
}
var cfg Config
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parse config %s: %w", path, err)
}
return &cfg, nil
}
// Define domain-specific errors
type ValidationError struct {
Field string
Message string
}
func (e *ValidationError) Error() string {
return fmt.Sprintf("validation failed on %s: %s", e.Field, e.Message)
}
// Sentinel errors for common cases
var (
ErrNotFound = errors.New("resource not found")
ErrUnauthorized = errors.New("unauthorized")
ErrInvalidInput = errors.New("invalid input")
)
func HandleError(err error) {
// Check for specific error
if errors.Is(err, sql.ErrNoRows) {
log.Println("No records found")
return
}
// Check for error type
var validationErr *ValidationError
if errors.As(err, &validationErr) {
log.Printf("Validation error on field %s: %s",
validationErr.Field, validationErr.Message)
return
}
// Unknown error
log.Printf("Unexpected error: %v", err)
}
// Bad: Ignoring error with blank identifier
result, _ := doSomething()
// Good: Handle or explicitly document why it's safe to ignore
result, err := doSomething()
if err != nil {
return err
}
// Acceptable: When error truly doesn't matter (rare)
_ = writer.Close() // Best-effort cleanup, error logged elsewhere
func WorkerPool(jobs <-chan Job, results chan<- Result, numWorkers int) {
var wg sync.WaitGroup
for i := 0; i < numWorkers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for job := range jobs {
results <- process(job)
}
}()
}
…
Build polished React and Next.js animations with reusable production-ready patterns.
Design security and risk controls for autonomous trading agents with transaction authority
Write and review React 18/19 components using modern best practices.
Get production-ready MySQL and MariaDB schema, query, and operations patterns.
Verify Laravel projects with environment checks, tests, security scans, and release readiness.
Audit Claude skills and commands with quick scans or full stocktakes.
Apply idiomatic Kotlin patterns to build robust, efficient, maintainable applications.
Learn idiomatic Rust patterns, ownership, concurrency, and robust error handling practices.
Write idiomatic Go tests, benchmarks, fuzz tests, and improve coverage.
Get idiomatic C# and .NET guidance for architecture, async, and dependency injection.
Learn Pythonic patterns, type hints, and best practices for maintainable code.
Apply modern Perl 5.36+ idioms and best practices for maintainable applications.