go-rest-api-example
Copilot instructions432 starsChanged 2 years agoMITView on GitHub
When generating code for this project, please ensure compliance with the following standards:
We split this copilot-instructions.md into the rules it gives an agent
35 rules. About 1 is common, 21 are distinctive, and 13 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈21
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 5
When generating code for this project, please ensure compliance with the following standards:
- Very specific: line 8
Follow Go conventions: Use gofmt, goimports, and standard Go idioms
- Distinctive: line 10
Use camelCase for variables and functions
- Distinctive: line 11
Use PascalCase for exported types and functions
- Distinctive: line 12
Use meaningful, descriptive names
- Very specific: line 13
Avoid abbreviations unless they're well-known (e.g., HTTP, URL, ID)
- Distinctive: line 16
golangci-lint: All generated code must pass our golangci-lint configuration
- Very specific: line 17
Verify before committing: Run make lint to check for linting issues locally
- Distinctive: line 19
No unused variables or imports
- Very specific: line 21
Use require for error assertions in tests, assert for other validations
- Distinctive: line 22
Avoid useless assertions (comparing variables to themselves)
- Common: line 23
Add proper context to error messages
- Very specific: line 27
Test naming: Use Test<FunctionName> pattern
- Distinctive: line 28
Test structure: Follow Arrange-Act-Assert pattern
- Very specific: line 29
Parallel tests: Use t.Parallel() for independent tests
- Very specific: line 30
Error testing: Use require.Error() for error assertions, assert for other checks
- Distinctive: line 32
Table-driven tests: Use for multiple test cases with similar structure
- Distinctive: line 109
Dependency Injection: Use interfaces and inject dependencies
- Distinctive: line 111
Interface Segregation: Keep interfaces small and focused
- Distinctive: line 116
Input Validation: Always validate and sanitize inputs
- Distinctive: line 117
Secrets Management: Never hardcode secrets, use environment variables or sidecar files
- Distinctive: line 118
SQL Injection Prevention: Use parameterized queries (though we use MongoDB)
- Distinctive: line 119
OWASP Compliance: Follow security headers and validation patterns
- Distinctive: line 125
Resource Management: Always close/cleanup resources (defer patterns)
- Very specific: line 130
Use the pkg/mongodb package for all database connections
- Distinctive: line 131
Follow the functional options pattern for configuration
- Distinctive: line 132
Always use context-aware operations
- Distinctive: line 136
Keep middleware focused and composable
- Distinctive: line 137
Use proper request ID propagation
- Very specific: line 142
Use the internal/config package for environment configuration
- Very specific: line 149
Format: Run gofmt -s -w . to format code
- Very specific: line 150
Lint: Run make lint to verify code passes all linting rules
- Very specific: line 151
Test: Run make test to ensure all tests pass
- Very specific: line 152
Build: Run make build to verify the application builds successfully
- Distinctive: line 162
When generating code, please ensure it follows these patterns and will pass both our linting rules and maintain consistency with the …
≈ “Common” is an estimate: at least 1 in 5 of the 3,669 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GitHub Copilot Instructions
Code Style & Quality Guidelines
When generating code for this project, please ensure compliance with the following standards:
Go Code Standards
- Follow Go conventions: Use
gofmt,goimports, and standard Go idioms - Naming conventions:
- Use camelCase for variables and functions
- Use PascalCase for exported types and functions
- Use meaningful, descriptive names
- Avoid abbreviations unless they're well-known (e.g.,
HTTP,URL,ID)
Linting Compliance
- golangci-lint: All generated code must pass our golangci-lint configuration
- Verify before committing: Run
make lintto check for linting issues locally - Common lint rules to follow:
- No unused variables or imports
- Proper error handling (never ignore errors)
- Use
requirefor error assertions in tests,assertfor other validations - Avoid useless assertions (comparing variables to themselves)
- Add proper context to error messages
- Fix issues promptly: Address all linting issues before submitting code
Testing Standards
- Test naming: Use
Test<FunctionName>pattern - Test structure: Follow Arrange-Act-Assert pattern
- Parallel tests: Use
t.Parallel()for independent tests - Error testing: Use
require.Error()for error assertions,assertfor other checks - Coverage: Aim for meaningful test coverage, not just line coverage
- Table-driven tests: Use for multiple test cases with similar structure
Package Organization
- Internal packages (
internal/): Private application codeconfig/: Configuration managementdb/: Database repositories and data accesshandlers/: HTTP request handlersmiddleware/: HTTP middleware componentsmodels/: Domain models and data structuresserver/: HTTP server setup and lifecycleutilities/: Internal utility functions
- Public packages (
pkg/): Reusable librarieslogger/: Structured logging utilitiesmongodb/: MongoDB connection management
Code Patterns to Follow
Error Handling
// Good: Proper error wrapping
if err != nil {
return fmt.Errorf("failed to process request: %w", err)
}
// Good: Context-aware operations
func (r *Repository) GetByID(ctx context.Context, id string) (*Model, error) {
// Implementation with proper context usage
}Testing Patterns
// Good: Table-driven tests
func TestFunction(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
expected string
wantErr bool
}{
// Test cases
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
// Test implementation
})
}
}MongoDB Patterns
// Good: Use functional options pattern
dbConnMgr, err := mongodb.NewMongoManager(
svcEnv.DBHosts,
svcEnv.DBName,
credentials,
mongodb.WithQueryLogging(true),
mongodb.WithReplicaSet("rs0"),
)Logging Patterns
// Good: Structured logging with context
lgr.Info().
Str("requestID", reqID).
Str("operation", "create_order").
Dur("elapsed", elapsed).
Msg("operation completed successfully")Architecture Principles
- Dependency Injection: Use interfaces and inject dependencies
- Single Responsibility: Each function/type should have one clear purpose
- Interface Segregation: Keep interfaces small and focused
- Error Boundaries: Handle errors at appropriate levels
- Context Propagation: Pass context through all operations that might be cancelled
Security Considerations
- Input Validation: Always validate and sanitize inputs
- Secrets Management: Never hardcode secrets, use environment variables or sidecar files
- SQL Injection Prevention: Use parameterized queries (though we use MongoDB)
- OWASP Compliance: Follow security headers and validation patterns
Performance Guidelines
- Connection Pooling: Reuse database connections
- Context Timeouts: Set appropriate timeouts for operations
- Graceful Shutdown: Implement proper cleanup on application termination
- Resource Management: Always close/cleanup resources (defer patterns)
Specific to This Project
MongoDB Connection Management
- Use the
pkg/mongodbpackage for all database connections - Follow the functional options pattern for configuration
- Always use context-aware operations
- Implement proper connection cleanup
Middleware Chain
- Keep middleware focused and composable
- Use proper request ID propagation
- Implement structured logging in middleware
- Handle panics gracefully
Configuration Management
- Use the
internal/configpackage for environment configuration - Validate all required configuration at startup
- Provide sensible defaults where appropriate
Development Workflow
Before Committing Code
- Format: Run
gofmt -s -w .to format code - Lint: Run
make lintto verify code passes all linting rules - Test: Run
make testto ensure all tests pass - Build: Run
make buildto verify the application builds successfully
Available Make Targets
make lint- Run golangci-lint to check for code quality issuesmake test- Run all unit testsmake ci-coverage- Run tests with coverage reportingmake build- Build the application binarymake docker-build- Build the Docker imagemake docker-start- Build and run the application in Docker
When generating code, please ensure it follows these patterns and will pass both our linting rules and maintain consistency with the existing codebase architecture.
Where files are headingNew Copilot instructions files have more rules about branches and pull requests, and fewer about code style.
Of the Copilot instructions files we read, the 2,297 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

