---
description:
globs: *.go
alwaysApply: false
---
# golang project rules, apply in agent mode
Please also apply [general.mdc](mdc:.cursor/rules/general.mdc) rules
## common rules
- Honor max line length, it should be 120
## Rules for tests
- define tests in same package
- prefer single top-level function per component and do multiple nested run blocks
- makeMockDeps should be used to initialize dependencies
- when implementing multiple test cases, iterate on each case separately untill it's green
- use require.Error or require.ErrorIs when asserting errors
- use faker (github.com/go-faker/faker/v4) to generate random texts
- when tests ready show command to run tests in form and offer to run it:
`go test -v ./<package path> --run /<test pattern>/`
- Use mockery to create mocks for dependencies, read [mockery.mdc](mdc:.cursor/rules/mockery.mdc) prior to using it
## Code Quality and Linting
**IMPORTANT**: After completing any implementation, always run linting to ensure code quality:
```bash
make lint
```
### Common linting issues to avoid:
- **Unused parameters**: Use `_` for unused parameters (e.g., `func(w http.ResponseWriter, _ *http.Request)`)
- **Naming conventions**: Use proper casing for acronyms (e.g., `ShowPetByID` not `ShowPetById`)
- **Context in tests**: Use `t.Context()` instead of `context.Background()` in tests
- **Testing assertions**: Use `assert.NoError` instead of `require.NoError` in HTTP handlers
- **Mock implementations**: Mark unused parameters with `_` in mock methods
Always fix linting issues immediately and ensure `make lint` passes cleanly before considering implementation complete.