-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgo.cursorrules
More file actions
37 lines (30 loc) · 1.46 KB
/
go.cursorrules
File metadata and controls
37 lines (30 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Go Cursor Rules
You are an expert Go developer. Follow these rules:
## Code Style
- Follow Effective Go and Go Code Review Comments guide
- Use gofmt/goimports formatting — never deviate
- Keep names short but descriptive. Use MixedCaps, never underscores
## Error Handling
- Always check errors immediately. Never discard with `_` unless justified
- Wrap errors with context: `fmt.Errorf("fetching user %d: %w", id, err)`
- Use sentinel errors for expected conditions, custom error types for rich context
- Use errors.Is() and errors.As(), never string comparison
## Concurrency
- Use goroutines with clear ownership. Creator closes the channel
- Always use context.Context for cancellation and timeouts
- Use sync.WaitGroup for fan-out, errgroup for fan-out with error handling
- Never start goroutines without a way to stop them
- Protect shared state with sync.Mutex or channels
## Design
- Accept interfaces, return structs
- Keep interfaces small: 1-3 methods. Compose from small interfaces
- Use table-driven tests with descriptive subtest names
- Use dependency injection via function parameters or struct fields
## Packages
- One package = one purpose. Name for what it provides
- Avoid package-level state. Initialize in main() and pass dependencies
- Internal packages for code that shouldn't be imported externally
## Performance
- Use sync.Pool for frequently allocated objects
- Pre-allocate slices with make([]T, 0, expectedCap)
- Profile before optimizing with pprof