Home › Go › Go Copilot path instructions

Go Copilot path instructions

Path-specific Copilot instructions (.instructions.md) for Go 1.27 code: errors, context, stdlib routing, and tests.

GitHub CopilotGo

How to use

Save this as .github/instructions/go.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.github/instructions/go.instructions.mdDownload  
---
applyTo: "**/*.go,go.mod"
description: Go conventions for this repository
---

# Go (1.27)

- Format with `gofmt`/`goimports`; lint with `golangci-lint run` and `go vet ./...`.
- Errors are values: return them, wrap with `fmt.Errorf("load user %d: %w", id, err)`, and check with `errors.Is`/`errors.As`. No `panic` for expected failures.
- `context.Context` is the first parameter of anything doing I/O; never store it in a struct. In tests use `t.Context()`.
- HTTP routing with the standard mux patterns (`mux.HandleFunc("GET /users/{id}", h)`, `r.PathValue("id")`) unless the repo already uses chi/gin/echo.
- Logging with `log/slog` structured key/values.
- Concurrency: prefer `errgroup` or `sync.WaitGroup.Go` over hand-rolled goroutine bookkeeping; every goroutine has a clear exit via context cancellation. Run `go test -race`.
- Accept interfaces, return concrete types; define interfaces where they're consumed and keep them small.
- Use generics only when they remove real duplication. Use `slices`, `maps`, and range-over-int/func from the stdlib.
- Pin dev tools with `tool` directives in `go.mod` and run them via `go tool <name>`.
- Tests are table-driven with `t.Run(tc.name, ...)`; use `httptest` for handlers and `testing/synctest` for time-dependent concurrency.

## Done when
`go build ./... && go vet ./... && go test -race ./...` pass.

More: all Go rules · all GitHub Copilot rules

Related rules

Go backend CLAUDE.md

CLAUDE.md for idiomatic Go HTTP services using the standard library, sqlc and table-driven tests.

Claude Code (CLAUDE.md)Go

Go CLI (Cobra) CLAUDE.md

CLAUDE.md for command-line tools in Go 1.27 with Cobra: commands, flags, output formats, exit codes, and tests.

Claude Code (CLAUDE.md)Go

Go concurrency Windsurf rules

Windsurf rules for safe Go concurrency: goroutine lifetimes, context cancellation, errgroup, channels, and the race detector.

WindsurfGo

Go + Gin web API Windsurf rules

Windsurf rules for Go 1.27 REST APIs built with Gin: handlers, binding/validation, middleware, and tests.

WindsurfGo

Go gRPC service rules

Cursor rules for gRPC services in Go with protobuf, buf for codegen and linting, interceptors, and status errors.

CursorGo

Go stdlib HTTP service AGENTS.md

AGENTS.md for Go 1.27 services using only net/http, slog, and database/sql or pgx, with no web framework.

AGENTS.mdGo

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.