use-modern-go

jetbrains/go-modern-guidelines · updated Jun 1, 2026

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

$npx skills add https://github.com/jetbrains/go-modern-guidelines --skill use-modern-go
0 commentsdiscussion
summary

!grep -rh "^go " --include="go.mod" . 2>/dev/null | cut -d' ' -f2 | sort | uniq -c | sort -nr | head -1 | xargs | cut -d' ' -f2 | grep . || echo unknown

skill.md

Modern Go Guidelines

Detected Go Version

!grep -rh "^go " --include="go.mod" . 2>/dev/null | cut -d' ' -f2 | sort | uniq -c | sort -nr | head -1 | xargs | cut -d' ' -f2 | grep . || echo unknown

How to Use This Skill

DO NOT search for go.mod files or try to detect the version yourself. Use ONLY the version shown above.

If version detected (not "unknown"):

  • Say: "This project is using Go X.XX, so I’ll stick to modern Go best practices and freely use language features up to and including this version. If you’d prefer a different target version, just let me know."
  • Do NOT list features, do NOT ask for confirmation

If version is "unknown":

  • Say: "Could not detect Go version in this repository"
  • Use AskUserQuestion: "Which Go version should I target?" → [1.23] / [1.24] / [1.25] / [1.26]

When writing Go code, use ALL features from this document up to the target version:

  • Prefer modern built-ins and packages (slices, maps, cmp) over legacy patterns
  • Never use features from newer Go versions than the target
  • Never use outdated patterns when a modern alternative is available

Features by Go Version

Go 1.0+

  • time.Since: time.Since(start) instead of time.Now().Sub(start)

Go 1.8+

  • time.Until: time.Until(deadline) instead of deadline.Sub(time.Now())

Go 1.13+

  • errors.Is: errors.Is(err, target) instead of err == target (works with wrapped errors)

Go 1.18+

  • any: Use any instead of interface{}
  • bytes.Cut: before, after, found := bytes.Cut(b, sep) instead of Index+slice
  • strings.Cut: before, after, found := strings.Cut(s, sep)

Go 1.19+

  • fmt.Appendf: buf = fmt.Appendf(buf, "x=%d", x) instead of []byte(fmt.Sprintf(...))
  • atomic.Bool/atomic.Int64/atomic.Pointer[T]: Type-safe atomics instead of atomic.StoreInt32
var flag atomic.Bool
flag.Store(true)
if flag.Load() { ... }

var ptr atomic.Pointer[Config]
ptr.Store(cfg)

Go 1.20+

  • strings.Clone: strings.Clone(s) to copy string without sharing memory
  • bytes.Clone: bytes.Clone(b) to copy byte slice
  • strings.CutPrefix/CutSuffix: if rest, ok := strings.CutPrefix(s, "pre:"); ok { ... }
  • errors.Join: errors.Join(err1, err2) to combine multiple errors
  • context.WithCancelCause: ctx, cancel := context.WithCancelCause(parent) then cancel(err)
  • context.Cause: context.Cause(ctx) to get the error that caused cancellation

Go 1.21+

Built-ins:

  • min/max: max(a, b) instead of if/else comparisons
  • clear: clear(m) to delete all map entries, clear(s) to zero slice elements

slices package:

  • slices.Contains: slices.Contains(items, x) instead of manual loops
  • slices.Index: slices.Index(items, x) returns index (-1 if not found)
  • slices.IndexFunc: slices.IndexFunc(items, func(item T) bool { return item.ID == id })
  • slices.SortFunc: slices.SortFunc(items, func(a, b T) int { return cmp.Compare(a.X, b.X) })
  • slices.Sort: slices.Sort(items) for ordered types
  • slices.Max/slices.Min: slices.Max(items) instead of manual loop
  • slices.Reverse: slices.Reverse(items) instead of manual swap loop
  • slices.Compact: slices.Compact(items) removes consecutive duplicates in-place
  • slices.Clip: slices.Clip(s) removes unused capacity
  • slices.Clone: slices.Clone(s) creates a copy

maps package:

  • maps.Clone: maps.Clone(m) instead of manual map iteration
  • maps.Copy: maps.Copy(dst, src) copies entries from src to dst
  • maps.DeleteFunc: maps.DeleteFunc(m, func(k K, v V) bool { return condition })

sync package:

  • sync.OnceFunc: f := sync.OnceFunc(func() { ... }) instead of sync.Once + wrapper
  • sync.OnceValue: getter := sync.OnceValue(func() T { return computeValue() })

context package:

  • context.AfterFunc: stop := context.AfterFunc(ctx, cleanup) runs cleanup on cancellation
  • context.WithTimeoutCause: ctx, cancel := context.WithTimeoutCause(parent, d, err)
  • context.WithDeadlineCause: Similar with deadline instead of duration

Go 1.22+

Loops:

  • for i := range n: for i := range len(items) instead of for i := 0; i < len(items); i++
  • Loop variables are now safe to capture in goroutines (each iteration has its own copy)

cmp package:

  • cmp.Or: cmp.Or(flag, env, config, "default") returns first non-zero value
// Instead of:
name := os.Getenv("NAME")
if name == "" {
    name = "default"
}
// Use:
name := cmp.Or(os.Getenv("NAME"), "default")

reflect package:

  • reflect.TypeFor: reflect.TypeFor[T]() instead of reflect.TypeOf((*T)(nil)).Elem()

net/http:

  • Enhanced http.ServeMux patterns: mux.HandleFunc("GET /api/{id}", handler) with method and path params
  • r.PathValue("id") to get path parameters

Go 1.23+

  • maps.Keys(m) / maps.Values(m) return iterators
  • slices.Collect(iter) not manual loop to build slice from iterator
  • slices.Sorted(iter) to collect and sort in one step
keys := slices.Collect(maps.Keys(m))       // not: for k := range m { keys = append(keys, k) }
sortedKeys := slices.Sorted(maps.Keys(m))  // collect + sort
for k := range maps.Keys(m) { process(k) } // iterate directly

time package

  • time.Tick: Use time.Tick freely — as of Go 1.23, the garbage collector can recover unreferenced tickers, even if they haven't been stopped. The Stop method is no longer necessary to help the garbage collector. There is no longer any reason to prefer NewTicker when Tick will do.

Go 1.24+

  • t.Context() not context.WithCancel(context.Background()) in tests. ALWAYS use t.Context() when a test function needs a context.

Before:

func TestFoo(t *testing.T) {
    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()
    result := doSomething(ctx)
}

After:

func TestFoo(t *testing.T) {
    ctx := t.Context()
    result := doSomething(ctx)
}
  • omitzero not omitempty in JSON struct tags. ALWAYS use omitzero for time.Duration, time.Time, structs, slices, maps.

Before:

type Config struct {
    Timeout time.Duration `json:"timeout,omitempty"` // doesn't work for Duration!
}

After:

type Config struct {
    Timeout time.Duration `json:"timeout,omitzero"`
}
  • b.Loop() not for i := 0; i < b.N; i++ in benchmarks. ALWAYS use b.Loop() for the main loop in benchmark functions.

Before:

func BenchmarkFoo(b *testing.B) {
    for i := 0; i < b.N; i++ {
        doWork()
    }
}

After:

func BenchmarkFoo(b *testing.B) {
    for b.Loop() {
        doWork()
    }
}
  • strings.SplitSeq not strings.Split when iterating. ALWAYS use SplitSeq/FieldsSeq when iterating over split results in a for-range loop.

Before:

for _, part := range strings.Split(s, ",") {
    process(part)
}

After:

for part := range strings.SplitSeq(s, ",") {
    process(part)
}

Also: strings.FieldsSeq, bytes.SplitSeq, bytes.FieldsSeq.

Go 1.25+

  • wg.Go(fn) not wg.Add(1) + go func() { defer wg.Done(); ... }(). ALWAYS use wg.Go() when spawning goroutines with sync.WaitGroup.

Before:

var wg sync.WaitGroup
for _, item := range items {
    wg.Add(1)
    go func() {
        defer wg.Done()
        process(item)
    }()
}
wg.Wait()

After:

var wg sync.WaitGroup
for _, item := range items {
    wg.Go(func() {
        process(item)
    })
}
wg.Wait()

Go 1.26+

  • new(val) not x := val; &x — returns pointer to any value. Go 1.26 extends new() to accept expressions, not just types. Type is inferred: new(0) → *int, new("s") → *string, new(T{}) → *T. DO NOT use x := val; &x pattern — always use new(val) directly. DO NOT use redundant casts like new(int(0)) — just write new(0). Common use case: struct fields with pointer types.

Before:

timeout := 30
debug := true
cfg := Config{
    Timeout: &timeout,
    Debug:   &debug,
}

After:

how to use use-modern-go

How to use use-modern-go 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 use-modern-go
2

Execute installation command

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

$npx skills add https://github.com/jetbrains/go-modern-guidelines --skill use-modern-go

The skills CLI fetches use-modern-go from GitHub repository jetbrains/go-modern-guidelines 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/use-modern-go

Reload or restart Cursor to activate use-modern-go. Access the skill through slash commands (e.g., /use-modern-go) 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.533 reviews
  • Chaitanya Patil· Dec 20, 2024

    Keeps context tight: use-modern-go is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Arjun Rao· Dec 8, 2024

    Registry listing for use-modern-go matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Mei Wang· Dec 4, 2024

    Keeps context tight: use-modern-go is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Arya Dixit· Nov 27, 2024

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

  • Zara Desai· Nov 23, 2024

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

  • Ama Ndlovu· Nov 19, 2024

    use-modern-go fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Piyush G· Nov 11, 2024

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

  • Arya Chawla· Oct 18, 2024

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

  • Zara Gupta· Oct 14, 2024

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

  • Fatima Lopez· Oct 10, 2024

    We added use-modern-go from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

showing 1-10 of 33

1 / 4