Copilot instructions for Go projects following idiomatic patterns, error handling, and standard project layout conventions.
## Go Copilot Custom Instructions
You are a Go expert for GitHub Copilot. Follow idiomatic Go conventions:
### Code Style
- Follow `gofmt` and `goimports` formatting strictly
- Keep functions short: under 30 lines, extract helpers for complex logic
- Use meaningful variable names; single letters only for short-lived loop vars
- Group related declarations with `var()` or `const()` blocks
- Comments on exported types and functions per `golint` requirements
### Error Handling
- Always check errors immediately: `if err != nil { return fmt.Errorf("context: %w", err) }`
- Wrap errors with `%w` for unwrapping; use `%v` only when wrapping is not needed
- Define sentinel errors: `var ErrNotFound = errors.New("not found")`
- Use custom error types implementing `Error()` for rich error information
- Never ignore errors with `_`; if truly ignorable, add a comment explaining why
### Project Layout
- Follow standard Go project layout: `cmd/`, `internal/`, `pkg/`
- `internal/` for private packages, `pkg/` only for genuinely reusable libraries
- One package per directory; package name matches directory name
- `main.go` in `cmd/appname/` for each binary
### Concurrency
- Use goroutines with `sync.WaitGroup` for fan-out patterns
- Always use `context.Context` as first parameter for cancellation
- Prefer channels for communication, mutexes for state protection
- Use `errgroup.Group` for concurrent tasks with error propagation
- Never start goroutines without a way to stop them
### Interfaces
- Define interfaces where they are used, not where they are implemented
- Keep interfaces small: 1-3 methods (io.Reader pattern)
- Accept interfaces, return structs
- Use `interface{}` only as `any` (Go 1.18+)
### Testing
- Table-driven tests with `t.Run()` subtests
- Use `testify/assert` and `testify/require` for assertions
- Test files: `*_test.go` in the same package
- Use `t.Helper()` in test helper functions
- Mock interfaces with generated mocks via `mockgen` or `moq`
### Dependencies
- Use Go modules; keep `go.mod` tidy with `go mod tidy`
- Prefer stdlib over third-party when quality is comparable
- Vendor dependencies for reproducible builds: `go mod vendor`Free to copy and use. Compatible with GitHub Copilot, GPT-5.
Add to .github/copilot-instructions.md in your Go repository. All Copilot suggestions will follow idiomatic Go patterns.
Initial release
Sign in and download this prompt to leave a review.