golang

saisudhir14/golang-agent-skill · updated May 28, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/saisudhir14/golang-agent-skill --skill golang
0 commentsdiscussion
summary

$22

skill.md

Go Best Practices

Production patterns from Google, Uber, and the Go team. Updated for Go 1.25.

Sub-skills: skills/go-error-handling, skills/go-concurrency, skills/go-testing, skills/go-performance, skills/go-code-review, skills/go-linting, skills/go-project-layout, skills/go-security. Deep-dive references in references/.

Core Principles

Readable code prioritizes these attributes in order:

  1. Clarity: purpose and rationale are obvious to the reader
  2. Simplicity: accomplishes the goal in the simplest way
  3. Concision: high signal to noise ratio
  4. Maintainability: easy to modify correctly
  5. Consistency: matches surrounding codebase

Error Handling

Full guide: skills/go-error-handling/SKILL.md | Reference: references/error-handling.md

  • Return errors, never panic in production code
  • Wrap with %w when callers need errors.Is/errors.As; use %v at boundaries
  • Keep context succinct: "new store: %w" not "failed to create new store: %w"
  • Handle errors once: don't log and return the same error
  • Error strings: lowercase, no punctuation
  • Indent error flow: handle errors first, keep happy path at minimal indentation
  • Use errors.Join (Go 1.20+) for multiple independent failures
  • Sentinel errors: Err prefix for vars, Error suffix for types
if err != nil {
    return fmt.Errorf("load config: %w", err)
}

Concurrency

Full guide: skills/go-concurrency/SKILL.md | Reference: references/concurrency.md

  • Channel size: 0 (unbuffered) or 1; anything else needs justification
  • Document goroutine lifetimes: when and how they exit
  • Use errgroup.Group over manual sync.WaitGroup for error-returning goroutines
  • Prefer synchronous functions: let callers add concurrency
  • Zero value mutexes: don't use pointers; don't embed in public structs
  • Typed atomics (Go 1.19+): atomic.Int64, atomic.Bool, atomic.Pointer[T]
  • sync.Map (Go 1.24+): significantly improved performance for disjoint key sets
g, ctx := errgroup.WithContext(ctx)
g.SetLimit(10)
for _, item := range items {
    g.Go(func() error { return process(ctx, item) })
}
return g.Wait()

Naming

  • MixedCaps always: never underscores (MaxLength not MAX_LENGTH)
  • Initialisms: consistent case (URL, ID, HTTP not Url, Id, Http)
  • Short variables: scope determines length (i for loops, DefaultTimeout for globals)
  • Receiver names: 1-2 letter abbreviation, consistent across methods, never this/self
  • Package names: lowercase single word, no util/common/misc
  • No repetition: http.Serve not http.HTTPServe; c.WriteTo not c.WriteConfigTo

Pointer vs Value Receivers

Pointer receiver Value receiver
Modifies receiver Small, immutable struct
Large struct Doesn't modify state
Contains sync.Mutex Map, func, or chan
Consistency with other methods Basic types

Imports

import (
    "context"
    "fmt"

    "github.com/google/uuid"
    "golang.org/x/sync/errgroup"

    "yourcompany/internal/config"
)
  • Three groups: stdlib, external, internal (separated by blank lines)
  • Rename only to avoid collisions
  • No dot imports except test files with circular deps
  • Blank imports (import _ "pkg") only in main or tests

Module Management (Go 1.24+)

Track tool dependencies in go.mod with tool directives:

tool (
    golang.org/x/tools/cmd/stringer
    github.com/golangci/golangci-lint/cmd/golangci-lint
)
go get -tool golang.org/x/tools/cmd/stringer  # add
go tool stringer -type=Status                  # run
go get tool                                    # update all
go install tool                                # install to GOBIN

Structs

  • Always use field names in initialization (positional breaks on changes)
  • Omit zero value fields
  • Don't embed types in public structs (exposes API unintentionally)
  • Use var for zero value structs: var user User

Slices and Maps

  • Nil slices preferred: var t []string (use []string{} only for JSON [] encoding)
  • Copy at boundaries: copy() or maps.Clone() to prevent mutation
  • Preallocate: make([]T, 0, len(input)) when size is known
  • Use slices and maps packages: slices.Sort, slices.Clone, maps.Clone, maps.Equal

Generics (Go 1.18+)

  • Use when writing identical code for different types
  • Use cmp.Ordered or custom constraints for type safety
  • Generic type aliases (Go 1.24+): type Set[T comparable] = map[T]struct{}
  • Don't over-generalize: use concrete types or interfaces when they suffice
func Filter[T any](s []T, pred func(T) bool) []T {
    result := make([]T, 0, len(s))
    for _, v := range s {
        if pred(v) {
            result = append(result, v)
        }
    }
    return result
}

Iterators (Go 1.23+)

Range over functions for custom iterators:

func Backward[T any](s []T) func(yield func(int, T) bool) {
    return func(yield func(int, T) bool) {
        for i := len(s) - 1; i >= 0; i-- {
            if !yield(i, s[i]) {
                return
            }
        }
    }
}

for i, v := range Backward(items) {
    fmt.Println(i, v)
}

String/bytes iterators (Go 1.24+): strings.Lines, strings.SplitSeq, strings.SplitAfterSeq


Structured Logging (Go 1.21+)

slog.Info("user created", "id", userID, "email", email)
slog.With("service", "auth").Info("starting")
handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})
  • slog.DiscardHandler (Go 1.24+) for suppressing logs in tests
  • Use consistent key names, group related fields with slog.Group

Performance

Full guide: skills/go-performance/SKILL.md | Reference: references/performance.md

  • strconv over fmt: strconv.Itoa(n) not fmt.Sprintf("%d", n)
  • Avoid repeated []byte conversions: store once, reuse
  • Preallocate map capacity: make(map[string]int, len(items))
  • strings.Builder with Grow() for concatenation

Testing

Full guide: skills/go-testing/SKILL.md | Reference: references/testing.md

  • Table-driven tests with t.Parallel() for subtests
  • go-cmp over reflect.DeepEqual for clear diff output
  • Useful failure messages: include input, got, want
  • t.Fatal for setup failures
  • Interfaces belong to consumers, not producers
  • T.Context and T.Chdir (Go 1.24+)
  • b.Loop() (Go 1.24+): cleaner benchmarks, no b.ResetTimer() needed
  • synctest.Test (Go 1.25+): deterministic concurrent testing with synthetic time

Resource Management (Go 1.24+)

  • runtime.AddCleanup: multiple cleanups per object, no cycle leaks (replaces SetFinalizer)
  • weak.Pointer[T]: weak references for caches, canonicalization, observers
  • os.Root: scoped file access preventing path traversal attacks

Patterns

Full reference: references/patterns.md

  • Functional options: WithTimeout(d), WithLogger(l) for configurable constructors
  • Interface compliance: var _ http.Handler = (*Handler)(nil)
  • Defer for cleanup: small overhead, worth the safety
  • Graceful shutdown: signal handling + srv.Shutdown(ctx)
  • Enums start at one: zero = invalid/unset
  • Use time.Duration: never raw ints for time
  • Two-value type assertions: t, ok := i.(string) to avoid panics
  • Context first: func Process(ctx context.Context, ...)
  • Avoid mutable globals: use dependency injection
  • Avoid init(): prefer explicit initialization in main
  • //go:embed (Go 1.16+): embed static files
  • Field tags: explicit json:"name" on marshaled structs
  • Container-aware GOMAXPROCS (Go 1.25+): automatic cgroup-based tuning

Common Gotchas

Full reference: references/gotchas.md

Gotcha Fix
Loop variable capture (pre-1.22) Fixed in Go 1.22+ (per-iteration vars)
Defer evaluates args immediately Capture in closure
Nil interface vs nil pointer Return nil explicitly
Use result before error check Always check err first (Go 1.25 enforces)
Map iteration order Sort keys with slices.Sorted(maps.Keys(m))
Slice append shared backing Full slice expression a[:2:2]

Linting

Full guide: skills/go-linting/SKILL.md

  • Use golangci-lint as the standard linter aggregator
  • Recommended linters: errcheck, govet, staticcheck, revive, gosimple, goimports, errorlint, bodyclose
  • Add as a tool dependency (Go 1.24+): go get -tool github.com/golangci/golangci-lint/cmd/golangci-lint
  • Run in CI: use golangci/golangci-lint-action for GitHub Actions
  • Suppress sparingly: prefer fixing over //nolint comments

Project Layout

Full guide: skills/go-project-layout/SKILL.md

  • cmd/: one subdirectory per executable, keep main.go thin
  • internal/: private packages, enforced by the Go toolchain
  • Avoid pkg/, src/, models/, utils/: name packages by purpose
  • Flat is fine: small projects should not have deep directory trees
  • Dockerfile: multi-stage build, CGO_ENABLED=0, distr
how to use golang

How to use golang on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add golang
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/saisudhir14/golang-agent-skill --skill golang

The skills CLI fetches golang from GitHub repository saisudhir14/golang-agent-skill and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/golang

Reload or restart Cursor to activate golang. Access the skill through slash commands (e.g., /golang) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.568 reviews
  • Nia Chen· Dec 28, 2024

    golang has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • William Mehta· Dec 24, 2024

    Solid pick for teams standardizing on skills: golang is focused, and the summary matches what you get after install.

  • Dhruvi Jain· Dec 20, 2024

    golang has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • William Khanna· Dec 8, 2024

    golang reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Soo Nasser· Dec 8, 2024

    Useful defaults in golang — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Sophia Thompson· Nov 27, 2024

    golang has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Dev Dixit· Nov 27, 2024

    I recommend golang for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Ren Rahman· Nov 19, 2024

    golang reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Oshnikdeep· Nov 11, 2024

    golang reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Sophia Sanchez· Oct 18, 2024

    golang fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

showing 1-10 of 68

1 / 7