Instruction file imported from ngduhaui/editervideo (
.github/instructions/languages/go/go.instructions.md). Copyright stays with the author.
GitHub Copilot Instructions
These instructions define how GitHub Copilot should assist with this Go project. The goal is to ensure consistent, high-quality code generation aligned with Go idioms, the chosen architecture, and our team's best practices.
š§ Context
- Project Type: CLI Tool / REST API / Microservice
- Language: Go
- Framework / Libraries: net/http, gorilla/mux, cobra, go.uber.org/zap, sqlx, testify
- Architecture: Clean Architecture with Repository Pattern
š§ General Guidelines
- Follow idiomatic Go conventions (https://go.dev/doc/effective_go).
- Use named functions over long anonymous ones.
- Organize logic into small, composable functions.
- Prefer interfaces for dependencies to enable mocking and testing.
- Use
gofmtorgoimportsto enforce formatting. - Avoid unnecessary abstraction; keep things simple and readable.
- Use
context.Contextfor request-scoped values and cancellation.
š File Structure
Use this structure as a guide when creating or updating files:
cmd/
myapp/
main.go
internal/
controller/
service/
repository/
model/
config/
middleware/
utils/
pkg/
logger/
errors/
tests/
unit/
integration/
š§¶ Patterns
ā Patterns to Follow
- Use Clean Architecture and Repository Pattern.
- Implement input validation using Go structs and validation tags (e.g., go-playground/validator).
- Use custom error types for wrapping and handling business logic errors.
- Logging should be handled via
zaporlog/slog. - Use dependency injection via constructors (avoid global state).
- Keep
main.gominimalādelegate tointernal.
š« Patterns to Avoid
- Donāt use global state unless absolutely required.
- Donāt hardcode configāuse environment variables or config files.
- Donāt panic or exit in library code; return errors instead.
- Donāt expose secretsāuse
.envor secret managers. - Avoid embedding business logic in HTTP handlers.
š§Ŗ Testing Guidelines
- Use
testingand testify for assertions and mocking. - Organize tests under
tests/unit/andtests/integration/. - Mock external services (e.g., DB, APIs) using interfaces and mocks for unit tests.
- Include table-driven tests for functions with many input variants.
- Follow TDD for core business logic.
š§© Example Prompts
Copilot, generate a REST endpoint using gorilla/mux that returns a list of users from a repository.Copilot, write a Go struct for user registration input with validation tags for email and required password.Copilot, implement a Cobra CLI command called āserveā that reads config from environment variables.Copilot, write a unit test for the CalculateDiscount function with multiple input cases using testify.Copilot, create a repository interface and its SQLX implementation for managing books.
š Iteration & Review
- Review Copilot output before committing.
- Refactor generated code to ensure readability and testability.
- Use comments to give Copilot context for better suggestions.
- Regenerate parts that are unidiomatic or too complex.