Skip to content
Skills Library
Programming · Building & coding

go

/go

Idiomatic programming style, patterns, and conventions for Go (Golang) development. Trigger when: - Writing, refactoring, reviewing, or debugging Go code. - Files matching the pattern **/*.go (including go.mod, go.sum) are in the workspace or referenced. - Tasks involve: go fmt, go test, go build, go vet, golangci-lint. - Prompt contains keywords: go, golang, goroutine, channel, select, interface, err != nil, defer, panic, gofmt, struct.

Author
nrdxp ↗
Repository
predicate ↗
Licence
MIT
Last repository change
31.08.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 31.08.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Idiomatic programming style, patterns, and conventions for Go (Golang) development. Trigger when: - Writing, refactoring, reviewing, or debugging Go code. - Files matching the pattern **/*.go (including go.mod, go.sum) are in the workspace or referenced. - Tasks involve: go fmt, go test, go build, go vet, golangci-lint. - Prompt contains keywords: go, golang, goroutine, channel, select, interface, err != nil, defer, panic, gofmt, struct.

Original author description

Idiomatic programming style, patterns, and conventions for Go (Golang) development. Trigger when: - Writing, refactoring, reviewing, or debugging Go code. - Files matching the pattern **/*.go (including go.mod, go.sum) are in the workspace or referenced. - Tasks involve: go fmt, go test, go build, go vet, golangci-lint. - Prompt contains keywords: go, golang, goroutine, channel, select, interface, err != nil, defer, panic, gofmt, struct.

How it works

  1. Core Philosophy
  2. Formatting
  3. Naming
  4. Functions
  5. Interfaces
  6. Pointers vs. Values
  7. Concurrency
  8. Error Handling
  9. Anti-Patterns
  10. Tooling
Original SKILL.md headings · 327 lines, 1,109 words
SKILL.md preview
---
name: go
description: |
  Idiomatic programming style, patterns, and conventions for Go (Golang) development.
  Trigger when:
  - Writing, refactoring, reviewing, or debugging Go code.
  - Files matching the pattern **/*.go (including go.mod, go.sum) are in the workspace or referenced.
  - Tasks involve: go fmt, go test, go build, go vet, golangci-lint.
  - Prompt contains keywords: go, golang, goroutine, channel, select, interface, err != nil, defer, panic, gofmt, struct.
---

# Go Language Idioms

Go favors simplicity, readability, and explicit behavior. Work with the language's conventions, not against them.

---

## Core Philosophy

- **Simplicity over cleverness** — clear, boring code is better than clever, obscure code
- **Explicit over implicit** — errors are values, not exceptions
- **Composition over inheritance** — embed types, implement interfaces
- **Share by communicating** — don't communicate by sharing memory

---

## Formatting

Let `gofmt` handle it. Don't fight the formatter.

```bash
gofmt -w .        # Format all files
go fmt ./...      # Format package
```

All Go code in the ecosystem follows `gofmt`. There is no debate.

---

## Naming

### General Rules

| Scope      | Style                  | Example                                       |
| :--------- | :--------------------- | :-------------------------------------------- |
| Exported   | `PascalCase`           | `ReadFile`, `HTTPClient`                      |
| Unexported | `camelCase`            | `readFile`, `httpClient`                      |
| Packages   | lowercase, single word | `bytes`, `http`, `bufio`                      |
| Acronyms   | All caps               | `HTTP`, `URL`, `ID` (not `Http`, `Url`, `Id`) |

### Package Names

- Short, concise, evocative
- No underscores or mixedCaps
- The package name is part of the type name: `bufio.Reader`, not `bufio.BufReader`

### Getters and Setters

```go
// ❌ Don't prefix getters with "Get"
func (u *User) GetName() string

// ✅ Just use the field name
func (u *User) Name() string

// ✅ Setters use "Set" prefix
func (u *User) SetName(name string)
```

### Interface Names

One-method interfaces use method name + `-er` suffix:

| Method   | Interface  |
| :------- | :--------- |
| `Read`   | `Reader`   |
| `Write`  | `Writer`   |
| `Close`  | `Closer`   |
| `String` | `Stringer` |

---

## Functions

### Multiple Return Values

Go functions return `(result, error)` instead of throwing:

```go
func ReadFile(path string) ([]byte, error) {
    f, err := os.Open(path)
    if err != nil {
        return nil, err
    }
    defer f.Close()
    return io.ReadAll(f)
}
```

### Named Return Values

Use for documentation, but avoid naked returns in non-trivial functions:

```go
// Named returns document what's being returned
func ParseDuration(s string) (duration time.Duration, err error) {
    // ...
    return duration, nil  // Explicit, not naked
}
```

### Defer

Use `defer` for cleanup. Defers execute LIFO at function exit:

```go
func CopyFile(dst, src string) error {
    r, err := os.Open(src)
    if err != nil {
        return err
    }
    defer r.Close()

    w, err := os.Create(dst)
    if err != nil {
        return err
    }
    defer w.Close()

    _, err = io.Copy(w, r)
    return err
}
```

---

## Interfaces

### Keep Interfaces Small

Accept interfaces, return concrete types:

```go
// ✅ Function accepts interface (flexible)
func Process(r io.Reader) error

// ✅ Function returns concrete type (useful)
func NewClient() *Client
```

### Interface Satisfaction

Interfaces are satisfied implicitly—no `implements` keyword:

```go
type Stringer interface {
    String() string
}

type User struct{ Name string }

// User satisfies Stringer automatically
func (u User) String() string {
    return u.Name
}
```

### Compile-Time Check

Verify interface satisfaction at compile time:

```go
var _ io.Reader = (*MyReader)(nil)
```

---

## Pointers vs. Values

### When to Use Pointer Receivers

| Use Pointer | When                                                 |
| :---------- | :--------------------------------------------------- |
| `*T`        | Method modifies the receiver                         |
| `*T`        | Struct is large (avoid copying)                      |
| `*T`        | Consistency (if any method uses pointer, all should) |

### When to Use Value Receivers

| Use Value | When                              |
| :-------- | :-------------------------------- |
| `T`       | Method doesn't modify receiver    |
| `T`       | Type is small (int, small struct) |
| `T`       | Type is immutable by design       |

---

## Concurrency

### Goroutines

Lightweight, start with `go`:

```go
go func() {
    // runs concurrently
}()
```

### Channels

Use channels for communication between goroutines:

```go
ch := make(chan int)       // Unbuffered
ch := make(chan int, 100)  // Buffered

ch <- value   // Send
v := <-ch     // Receive
```

### Share by Communicating

> "Don't communicate by sharing memory; share memory by communicating."

```go
// ❌ Shared state with mutex
var count int
var mu sync.Mutex

// ✅ Channel-based coordination
type result struct{ value int }
results := make(chan result)
```

### Common Patterns

| Pattern           | Use Case                          |
| :---------------- | :-------------------------------- |
| `sync.WaitGroup`  | Wait for N goroutines to complete |
| `context.Context` | Cancellation and timeouts         |
| `select`          | Multiplex channel operations      |
| `sync.Once`       | One-time initialization           |

---

## Error Handling

### Errors Are Values

Check explicitly. Never discard with `_`:

```go
// ❌ Never ignore errors
result, _ := doSomething()

// ✅ Always check
result, err := doSomething()
if err != nil {
    return fmt.Errorf("doing something: %w", err)
}
```

### Error Wrapping

Use `%w` to wrap errors with context:

```go
if err != nil {
    return fmt.Errorf("failed to parse config %s: %w", path, err)
}
```

### Custom Errors

For libraries, define sentinel errors or custom types:

```go
// Sentinel errors
var ErrNotFound = errors.New("not found")

// Custom error types
type ValidationError struct {
    Field   string
    Message string
}

func (e *ValidationError) Error() string {
    return fmt.Sprintf("%s: %s", e.Field, e.Message)
}
```

### When to Panic

| Context           | Panic?        | Alternative       |
| :---------------- | :------------ | :---------------- |
| Library code      | ❌ Never      | Return `error`    |
| Impossible states | ✅ Acceptable | Assert invariants |
| Init failures     | ✅ Acceptable | `log.Fatal`       |

---

## Anti-Patterns

| Anti-Pattern            | Description                                  | Remedy                                             |
| :---------------------- | :------------------------------------------- | :------------------------------------------------- |
| **Ignoring errors**     | Using `_` to discard errors                  | Always check or explicitly document why ignored    |
| **Naked returns**       | `return` without values in complex functions | Use explicit return values                         |
| **Interface pollution** | Defining interfaces before needed            | Define interfaces at point of use                  |
| **Premature channels**  | Using channels when mutex suffices           | Start simple; add concurrency primitives as needed |
| **Giant interfaces**    | Interfaces with many methods                 | Keep interfaces small; compose when needed         |

---

## Tooling

```bash
go fmt ./...           # Format code
go vet ./...           # Static analysis
golangci-lint run      # Comprehensive linting
go test ./...          # Run tests
go test -race ./...    # Detect race conditions
```

---

## Quick Reference

- **Errors are values** — check explicitly, wrap with context
- **Accept interfaces, return structs** — flexible inputs, concrete outputs
- **Use `gofmt`** — no formatting debates
- **Prefer composition** — embed types, small interfaces
- **Channels for coordination** — share by communicating
- **`defer` for cleanup** — runs at function exit, LIFO
- **No naked returns** — be explicit in non-trivial functions

> These idioms refine but are subordinate to the [Code-Edit Constraints](../../ambient.md#code-edit-constraints).

Versions

RepositoryScoreLicence
This page · nrdxp/predicate100MIT
ericrisco/rsc-harness100MIT
terrylica/cc-skills100MIT
maragudk/fabrik100MIT
znlgis/opengis-skills100MIT
dilhanz/ship100MIT
chrs-myrs/livespec100MIT
nimadorostkar/Claude-Skills-collection100MIT
appwrite/claude-plugin100BSD-3-Clause

Database snapshot: 13.11.2026 · package version 67450b3c5bed (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90golang
    Idiomatic Go guidance for writing and reviewing Go code - style, naming, MixedCaps, GoDoc comments, error handling (%w, errors.Is/As, sentinel errors), goroutines/channels/select/context, safety (nil maps, append aliasing, type assertions), structs/interfaces, generics,…
  • 100go-ops
    Go development patterns, concurrency, error handling, testing, and project structure. Use for: golang, go, goroutine, channel, context, errgroup, go test, go mod, go build, interface, generics, table-driven tests, worker pool, sync.Mutex, sync.WaitGroup, pprof, go vet,…
  • 95building-go-projects
    Sets up and maintains Go projects with a CI gate that actually gates — module-path correctness, golangci-lint config that matches the installed major version, deterministic gofmt, a pinned toolchain, and meaningful test/lint jobs. Use when creating a Go module, wiring GitHub…
  • 95python
    Idiomatic programming style, patterns, and conventions for Python development. Trigger when: - Writing, refactoring, reviewing, or debugging Python code. - Files matching the pattern **/*.py (including requirements.txt, pyproject.toml, setup.py) are in the workspace or…
  • 100rust
    Idiomatic programming style, patterns, and conventions for Rust development. Trigger when: - Writing, refactoring, reviewing, or debugging Rust code. - Files matching the pattern **/*.rs (including Cargo.toml, Cargo.lock) are in the workspace or referenced. - Tasks involve:…
  • 100golang-expert
    Senior Go engineer and technical advisor — use for any Go question, design decision, or implementation task. Covers idiomatic patterns, concurrency, error handling, project structure, performance optimisation, observability, and testing. Invoke whenever the user is writing,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.