## Code Quality Rules
- Follow Go's official style guide and idioms from "Effective Go"
- Use proper error handling with explicit checks (`if err != nil`)
- Prefer composition over inheritance
- Write concise, descriptive function and variable names
- Include appropriate comments for complex logic and exported functions/types
- Use proper package organization and naming
- Implement proper resource cleanup (defer, close, etc.)
- Apply consistent formatting (use gofmt standards)
- Favor readability over excessive optimization
- Use appropriate Go concurrency patterns (goroutines, channels, sync package)
## Architecture and Design Rules
- Follow SOLID principles where applicable
- Use interfaces for flexible and testable code
- Separate concerns (business logic, data access, presentation)
- Design for testability
- Create small, focused packages with clear responsibilities
- Use dependency injection for better testing and flexibility
- Implement proper error types and handling strategies
- Design APIs with consistency and backward compatibility in mind
- Apply appropriate design patterns but avoid over-engineering
- Consider performance implications of design choices
## Testing Rules
- Write comprehensive unit tests for all functionality
- Use table-driven tests for clear and concise test cases
- Implement integration tests for critical paths
- Use appropriate mocks and test doubles
- Test error conditions and edge cases
- Benchmark performance-critical code
- Use Go's built-in testing tools (testing package, benchmarks)
- Practice test-driven development when appropriate
- Keep tests maintainable and understandable
- Ensure adequate test coverage
## Performance and Optimization Rules
- Use appropriate data structures and algorithms
- Profile before optimizing (pprof)
- Optimize for memory efficiency in large-scale systems
- Consider CPU and I/O bound operations
- Use buffered operations for I/O intensive tasks
- Apply concurrency with caution and purpose
- Design for scalability from the beginning
- Minimize allocations in performance-critical paths
- Use sync.Pool for frequent allocations
- Consider cache-friendly data structures
## Security Rules
- Validate all user inputs
- Sanitize data before using in SQL, templates, etc.
- Use secure cryptographic practices
- Implement proper authentication and authorization
- Handle sensitive data carefully (passwords, tokens)
- Use the principle of least privilege
- Check for common security vulnerabilities (OWASP)
- Consider rate limiting for public APIs
- Implement proper logging (without sensitive data)
- Keep dependencies updated and scan for vulnerabilities
## Documentation Rules
- Document all exported functions, types, and constants
- Provide clear package documentation
- Include examples in documentation when helpful
- Document concurrency considerations
- Explain non-obvious design choices
- Document known limitations and edge cases
- Include usage examples for complex APIs
- Keep documentation up-to-date with code changes
- Document error conditions and handling
- Use godoc compatible documentation style
I need comprehensive Go test codes for my project. For each request, please:
- Analyze the Go code I provide
- Create thorough test cases that follow Go best practices
- Include both unit tests and integration tests where appropriate
- Use table-driven test patterns for testing multiple scenarios
- Implement mocks for external dependencies
- Test happy paths, edge cases, and error conditions
- Use assertions appropriate for Go (standard library testing or testify)
- Follow Go testing conventions (TestXxx function naming, *testing.T parameters)
- Include benchmark tests for performance-critical functions
- Provide clear test descriptions and comments
- Consider test coverage and aim for comprehensive testing
- Structure tests to be maintainable and readable
When generating tests:
- Use Go's native testing framework or suggest appropriate testing libraries
- Properly handle setup and teardown with t.Cleanup() where needed
- Include examples of how to run the tests
- Suggest any improvements to the original code that would improve testability
- Highlight any potentially uncovered edge cases
Your response should provide complete, runnable test codes that is ready to be added to my project.
No Data configured
No MCP Servers configured