agentleFS
carloss765carloss765/agent-skills/.claude/skills/golang-extension/SKILL.md

go-development

Skill1 starsChanged 11 months agoISCView on GitHub

Guidelines for writing idiomatic, efficient, and concurrent Go code. Use when working with .go files, building Go services, APIs, or CLI tools.

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

61 rules. 0 are common, 60 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 60

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 11
  2. Distinctive:

    Composition Over Inheritance: Use struct embedding and interfaces, not class hierarchies.

    line 21
  3. Distinctive:

    Standard Library First: Use standard library before adding dependencies.

    line 23
  4. Distinctive:

    Effective Go: Follow patterns and practices from Effective Go documentation.

    line 24
  5. Distinctive:

    Package Names: Use short, lowercase, single-word package names.

    line 29
  6. Distinctive:

    Internal Packages: Use internal/ directory for private packages.

    line 30
  7. Very specific:

    Main Package: Keep main.go minimal. Move logic to packages.

    line 31
  8. Distinctive:

    Flat Structure: Avoid deep nesting. Prefer flat package hierarchies.

    line 32
  9. Distinctive:

    Go Modules: Use go.mod for dependency management (Go 1.11+).

    line 33
  10. Distinctive:

    CamelCase: Use MixedCaps or mixedCaps, not underscores.

    line 38
  11. Distinctive:

    Short Names: Use short variable names in small scopes (i, err, ctx).

    line 39
  12. Distinctive:

    Descriptive Names: Use descriptive names for package-level declarations.

    line 40
  13. Distinctive:

    Getters: Don't use Get prefix for getters (use Value() not GetValue()).

    line 41
  14. Distinctive:

    Function Length: Keep functions focused and concise.

    line 46
  15. Distinctive:

    Multiple Return Values: Use multiple returns for value and error.

    line 47
  16. Distinctive:

    Named Return Values: Use named returns for documentation, not for early return tricks.

    line 48
  17. Distinctive:

    Receiver Names: Use short, consistent receiver names (1-2 letters).

    line 49
  18. Distinctive:

    Pointer vs Value Receivers: Use pointer receivers for mutation or large structs.

    line 50
  19. Distinctive:

    Function Options: Use functional options pattern for configuration.

    line 51
  20. Distinctive:

    Check All Errors: Never ignore errors. Always check returned error values.

    line 55
  21. Distinctive:

    Error Messages: Don't capitalize error messages or end with punctuation.

    line 56
  22. Distinctive:

    Error Wrapping: Use fmt.Errorf with %w verb to wrap errors (Go 1.13+).

    line 57
  23. Distinctive:

    Custom Errors: Create custom error types for domain-specific errors.

    line 58
  24. Distinctive:

    Sentinel Errors: Use errors.Is and errors.As for error comparison.

    line 59
  25. Distinctive:

    Error Context: Add context to errors as they propagate up the call stack.

    line 60
  26. Distinctive:

    Small Interfaces: Keep interfaces small and focused (1-3 methods ideal).

    line 64
  27. Distinctive:

    Empty Interface: Use interface{} (or any in Go 1.18+) sparingly.

    line 66
  28. Distinctive:

    Type Assertions: Check type assertions with comma-ok idiom.

    line 67
  29. Distinctive:

    Struct Tags: Use struct tags for encoding/decoding (json, xml, yaml).

    line 68
  30. Distinctive:

    Channels: Use channels to communicate between goroutines, not shared memory.

    line 74
  31. Distinctive:

    Select Statement: Use select for multiplexing channel operations.

    line 75
  32. Distinctive:

    Context Package: Use context.Context for cancellation and deadlines.

    line 76
  33. Distinctive:

    WaitGroups: Use sync.WaitGroup to wait for goroutines to complete.

    line 77
  34. Distinctive:

    Mutexes: Use sync.Mutex when shared memory is unavoidable.

    line 78
  35. Distinctive:

    Buffered Channels: Use buffered channels carefully to avoid deadlocks.

    line 79
  36. Distinctive:

    String Builder: Use strings.Builder for efficient string concatenation.

    line 85
  37. Distinctive:

    Defer: Use defer for cleanup, but be aware of performance in loops.

    line 86
  38. Distinctive:

    Table-Driven Tests: Use table-driven tests for multiple test cases.

    line 92
  39. Distinctive:

    Subtests: Use t.Run() for subtests and parallel execution.

    line 93
  40. Distinctive:

    Test Helpers: Create test helper functions with t.Helper().

    line 94
  41. Distinctive:

    Benchmarks: Write benchmarks for performance-critical code.

    line 95
  42. Distinctive:

    Coverage: Use go test -cover to measure test coverage.

    line 96
  43. Distinctive:

    Mocking: Use interfaces for dependency injection and testing.

    line 97
  44. Distinctive:

    Not closing channels (unless infinite)

    line 127
  45. Distinctive:

    HTTP: Use net/http for HTTP servers and clients.

    line 133
  46. Distinctive:

    JSON: Use encoding/json for JSON marshaling.

    line 134
  47. Distinctive:

    Time: Use time.Time, never store time as strings or integers.

    line 135
  48. Distinctive:

    Context: Use context.Context in all I/O operations.

    line 136
  49. Distinctive:

    Formatting: Use fmt.Sprintf for string formatting, not string concatenation.

    line 137
  50. Distinctive:

    Logging: Use log or slog (Go 1.21+) for structured logging.

    line 138
  51. Distinctive:

    Go Modules: Use go mod init, go mod tidy for module management.

    line 142
  52. Distinctive:

    Semantic Versioning: Follow semver for module versions.

    line 143
  53. Distinctive:

    Minimal Dependencies: Add dependencies judiciously.

    line 144
  54. Distinctive:

    Replace Directive: Use replace in go.mod for local development only.

    line 145
  55. Distinctive:

    Vendor Directory: Use go mod vendor for reproducible builds.

    line 146
  56. Distinctive:

    Profiling: Use pprof for CPU and memory profiling.

    line 150
  57. Distinctive:

    Benchmarking: Write benchmarks before optimizing.

    line 151
  58. Distinctive:

    String Operations: Use strings.Builder or bytes.Buffer for concatenation.

    line 152
  59. Distinctive:

    Reflection: Avoid reflection in hot paths.

    line 153
  60. Distinctive:

    sync.Pool: Use sync.Pool for object reuse in high-throughput scenarios.

    line 155
  61. Distinctive:

    Before submitting Go code, verify:

    line 159

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Go Development Skills

When to Use This Skill

Use this skill when:

  • Writing or refactoring Go code (.go files)
  • Building microservices, APIs, or backend systems
  • Creating CLI tools or system utilities
  • Working with concurrent programming and goroutines
  • Developing cloud-native applications

I. Go Philosophy & Principles

  • Simplicity First: Embrace Go's philosophy of simplicity and clarity over cleverness.
  • Composition Over Inheritance: Use struct embedding and interfaces, not class hierarchies.
  • Explicit Error Handling: Handle errors explicitly. Don't ignore returned errors.
  • Standard Library First: Use standard library before adding dependencies.
  • Effective Go: Follow patterns and practices from Effective Go documentation.

II. Code Organization & Structure

  • Package Organization: Organize by functionality, not by type (models, controllers, etc.).
  • Package Names: Use short, lowercase, single-word package names.
  • Internal Packages: Use internal/ directory for private packages.
  • Main Package: Keep main.go minimal. Move logic to packages.
  • Flat Structure: Avoid deep nesting. Prefer flat package hierarchies.
  • Go Modules: Use go.mod for dependency management (Go 1.11+).

III. Naming Conventions

  • Exported Names: Capitalize first letter for exported identifiers.
  • CamelCase: Use MixedCaps or mixedCaps, not underscores.
  • Short Names: Use short variable names in small scopes (i, err, ctx).
  • Descriptive Names: Use descriptive names for package-level declarations.
  • Getters: Don't use Get prefix for getters (use Value() not GetValue()).
  • Interfaces: Name interfaces with -er suffix (Reader, Writer, Closer).

IV. Functions & Methods

  • Function Length: Keep functions focused and concise.
  • Multiple Return Values: Use multiple returns for value and error.
  • Named Return Values: Use named returns for documentation, not for early return tricks.
  • Receiver Names: Use short, consistent receiver names (1-2 letters).
  • Pointer vs Value Receivers: Use pointer receivers for mutation or large structs.
  • Function Options: Use functional options pattern for configuration.

V. Error Handling

  • Check All Errors: Never ignore errors. Always check returned error values.
  • Error Messages: Don't capitalize error messages or end with punctuation.
  • Error Wrapping: Use fmt.Errorf with %w verb to wrap errors (Go 1.13+).
  • Custom Errors: Create custom error types for domain-specific errors.
  • Sentinel Errors: Use errors.Is and errors.As for error comparison.
  • Error Context: Add context to errors as they propagate up the call stack.

VI. Interfaces & Types

  • Small Interfaces: Keep interfaces small and focused (1-3 methods ideal).
  • Accept Interfaces: Accept interfaces as parameters, return concrete types.
  • Empty Interface: Use interface{} (or any in Go 1.18+) sparingly.
  • Type Assertions: Check type assertions with comma-ok idiom.
  • Struct Tags: Use struct tags for encoding/decoding (json, xml, yaml).
  • Zero Values: Design types so their zero value is useful.

VII. Concurrency

  • Goroutines: Launch goroutines for concurrent tasks, but manage their lifecycle.
  • Channels: Use channels to communicate between goroutines, not shared memory.
  • Select Statement: Use select for multiplexing channel operations.
  • Context Package: Use context.Context for cancellation and deadlines.
  • WaitGroups: Use sync.WaitGroup to wait for goroutines to complete.
  • Mutexes: Use sync.Mutex when shared memory is unavoidable.
  • Buffered Channels: Use buffered channels carefully to avoid deadlocks.

VIII. Memory Management

  • Pointers vs Values: Pass large structs by pointer. Pass small values by value.
  • Slice Capacity: Pre-allocate slices with make() when size is known.
  • String Builder: Use strings.Builder for efficient string concatenation.
  • Defer: Use defer for cleanup, but be aware of performance in loops.
  • Memory Leaks: Close channels and cancel contexts to prevent goroutine leaks.

IX. Testing

  • Test Files: Name test files *_test.go in the same package.
  • Table-Driven Tests: Use table-driven tests for multiple test cases.
  • Subtests: Use t.Run() for subtests and parallel execution.
  • Test Helpers: Create test helper functions with t.Helper().
  • Benchmarks: Write benchmarks for performance-critical code.
  • Coverage: Use go test -cover to measure test coverage.
  • Mocking: Use interfaces for dependency injection and testing.

X. Project Structure

Standard Go Project Layout:

project/
├── cmd/              # Main applications
├── internal/         # Private application code
├── pkg/              # Public library code
├── api/              # API definitions (proto, OpenAPI)
├── configs/          # Configuration files
├── scripts/          # Build and automation scripts
├── test/             # Integration tests
├── go.mod            # Module definition
└── README.md

XI. Common Patterns

Good Patterns:

  • Functional options for configuration
  • Singleton with sync.Once
  • Worker pools with goroutines and channels
  • Pipeline pattern with channels
  • Context for cancellation propagation

Anti-Patterns to Avoid:

  • Ignoring errors with _ = err
  • Using panic for normal error handling
  • Not closing channels (unless infinite)
  • Goroutine leaks (no cleanup mechanism)
  • Premature optimization

XII. Standard Library Usage

  • HTTP: Use net/http for HTTP servers and clients.
  • JSON: Use encoding/json for JSON marshaling.
  • Time: Use time.Time, never store time as strings or integers.
  • Context: Use context.Context in all I/O operations.
  • Formatting: Use fmt.Sprintf for string formatting, not string concatenation.
  • Logging: Use log or slog (Go 1.21+) for structured logging.

XIII. Dependencies & Modules

  • Go Modules: Use go mod init, go mod tidy for module management.
  • Semantic Versioning: Follow semver for module versions.
  • Minimal Dependencies: Add dependencies judiciously. Prefer standard library.
  • Replace Directive: Use replace in go.mod for local development only.
  • Vendor Directory: Use go mod vendor for reproducible builds.

XIV. Performance & Optimization

  • Profiling: Use pprof for CPU and memory profiling.
  • Benchmarking: Write benchmarks before optimizing.
  • String Operations: Use strings.Builder or bytes.Buffer for concatenation.
  • Reflection: Avoid reflection in hot paths. It's slow.
  • Allocations: Minimize heap allocations in performance-critical code.
  • sync.Pool: Use sync.Pool for object reuse in high-throughput scenarios.

XV. Best Practices Checklist

Before submitting Go code, verify:

  • All errors are checked and handled
  • Code formatted with gofmt or goimports
  • No goroutine leaks (proper cleanup)
  • Interfaces are small and focused
  • Tests written and passing
  • Error messages are lowercase, unwrapped
  • Context used for cancellation
  • No global mutable state
  • Receiver names are consistent
  • go mod tidy run before commit

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.