agentleFS
rameshsunkararameshsunkara/go-rest-api-example/.github/copilot-instructions.md

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
  1. Distinctive:

    When generating code for this project, please ensure compliance with the following standards:

    line 5
  2. Very specific:

    Follow Go conventions: Use gofmt, goimports, and standard Go idioms

    line 8
  3. Distinctive:

    Use camelCase for variables and functions

    line 10
  4. Distinctive:

    Use PascalCase for exported types and functions

    line 11
  5. Distinctive:

    Use meaningful, descriptive names

    line 12
  6. Very specific:

    Avoid abbreviations unless they're well-known (e.g., HTTP, URL, ID)

    line 13
  7. Distinctive:

    golangci-lint: All generated code must pass our golangci-lint configuration

    line 16
  8. Very specific:

    Verify before committing: Run make lint to check for linting issues locally

    line 17
  9. Distinctive:

    No unused variables or imports

    line 19
  10. Very specific:

    Use require for error assertions in tests, assert for other validations

    line 21
  11. Distinctive:

    Avoid useless assertions (comparing variables to themselves)

    line 22
  12. Common:

    Add proper context to error messages

    line 23
  13. Very specific:

    Test naming: Use Test<FunctionName> pattern

    line 27
  14. Distinctive:

    Test structure: Follow Arrange-Act-Assert pattern

    line 28
  15. Very specific:

    Parallel tests: Use t.Parallel() for independent tests

    line 29
  16. Very specific:

    Error testing: Use require.Error() for error assertions, assert for other checks

    line 30
  17. Distinctive:

    Table-driven tests: Use for multiple test cases with similar structure

    line 32
  18. Distinctive:

    Dependency Injection: Use interfaces and inject dependencies

    line 109
  19. Distinctive:

    Interface Segregation: Keep interfaces small and focused

    line 111
  20. Distinctive:

    Input Validation: Always validate and sanitize inputs

    line 116
  21. Distinctive:

    Secrets Management: Never hardcode secrets, use environment variables or sidecar files

    line 117
  22. Distinctive:

    SQL Injection Prevention: Use parameterized queries (though we use MongoDB)

    line 118
  23. Distinctive:

    OWASP Compliance: Follow security headers and validation patterns

    line 119
  24. Distinctive:

    Resource Management: Always close/cleanup resources (defer patterns)

    line 125
  25. Very specific:

    Use the pkg/mongodb package for all database connections

    line 130
  26. Distinctive:

    Follow the functional options pattern for configuration

    line 131
  27. Distinctive:

    Always use context-aware operations

    line 132
  28. Distinctive:

    Keep middleware focused and composable

    line 136
  29. Distinctive:

    Use proper request ID propagation

    line 137
  30. Very specific:

    Use the internal/config package for environment configuration

    line 142
  31. Very specific:

    Format: Run gofmt -s -w . to format code

    line 149
  32. Very specific:

    Lint: Run make lint to verify code passes all linting rules

    line 150
  33. Very specific:

    Test: Run make test to ensure all tests pass

    line 151
  34. Very specific:

    Build: Run make build to verify the application builds successfully

    line 152
  35. Distinctive:

    When generating code, please ensure it follows these patterns and will pass both our linting rules and maintain consistency with the …

    line 162

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

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 lint to check for linting issues locally
  • Common lint rules to follow:
    • No unused variables or imports
    • Proper error handling (never ignore errors)
    • Use require for error assertions in tests, assert for 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, assert for 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 code
    • config/: Configuration management
    • db/: Database repositories and data access
    • handlers/: HTTP request handlers
    • middleware/: HTTP middleware components
    • models/: Domain models and data structures
    • server/: HTTP server setup and lifecycle
    • utilities/: Internal utility functions
  • Public packages (pkg/): Reusable libraries
    • logger/: Structured logging utilities
    • mongodb/: 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/mongodb package 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/config package for environment configuration
  • Validate all required configuration at startup
  • Provide sensible defaults where appropriate

Development Workflow

Before Committing Code

  1. Format: Run gofmt -s -w . to format code
  2. Lint: Run make lint to verify code passes all linting rules
  3. Test: Run make test to ensure all tests pass
  4. Build: Run make build to verify the application builds successfully

Available Make Targets

  • make lint - Run golangci-lint to check for code quality issues
  • make test - Run all unit tests
  • make ci-coverage - Run tests with coverage reporting
  • make build - Build the application binary
  • make docker-build - Build the Docker image
  • make 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.

Download now (ZIP)

  • 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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.