Go backend development best practices for microservices with clean architecture, observability, and production-ready patterns
Install
npx skills add https://github.com/mindrally/skills --skill go-backend-microservicesSKILL.md
Go Backend Development for Microservices
Core Principles
- Apply Clean Architecture with clear separation into handlers, services, repositories, and domain models
- Prioritize interface-driven development with explicit dependency injection
- Write short, focused functions with a single responsibility
- Ensure safe use of goroutines, and guard shared state with channels or sync primitives
Project Structure
Maintain modular project structure with clear directories:
project/
├── cmd/ # Application entry points
├── internal/ # Private application code
├── pkg/ # Public library code
├── api/ # API definitions (OpenAPI, protobuf)
├── configs/ # Configuration files
└── test/ # Additional test utilities
Error Handling
- Always check and handle errors explicitly
- Use wrapped errors for traceability:
fmt.Errorf("context: %w", err) - Create custom error types for domain-specific errors
- Return errors up the call stack with appropriate context
- Log errors at the appropriate level with sufficient context
Context Propagation
- Use context propagation for request-scoped values, deadlines, and cancellations
- Pass context as the first parameter to functions
- Respect context cancellation in long-running operations
- Set appropriate timeouts for external calls
Observability
Implement OpenTelemetry for comprehensive observability:
Distributed Tracing
- Add spans for significant operations
- Propagate trace context across service boundaries
- Include relevant attributes in spans
Metrics
- Implement custom metrics for business operations
- Use standard metric types (counters, gauges, histograms)
- Export metrics in Prometheus format
Structured Logging
- Use structured logging with consistent field names
- Include trace IDs in log entries
- Log at appropriate levels (debug, info, warn, error)
Security
- Apply input validation rigorously on all external inputs
- Use secure defaults for JWT tokens and cookies
- Implement proper authentication and authorization
- Sanitize data before logging to avoid leaking sensitive information
- Use prepared statements for database queries
Testing
Unit Tests
- Write table-driven unit tests with adequate coverage
- Use parallel test execution where safe
- Mock external dependencies using interfaces
- Focus on testing business logic
Integration Tests
- Separate integration tests from unit tests
- Use test containers for database and service dependencies
- Test actual API endpoints and responses
Concurrency
- Use goroutines appropriately for concurrent operations
- Guard shared state with channels or sync primitives
- Implement proper graceful shutdown
- Use worker pools for bounded concurrency
Documentation
- Document with GoDoc-style comments
- Keep comments up to date with code changes
- Document public APIs thoroughly
- Include examples in documentation where helpful
CI/CD Integration
- Maintain CI integration for linting and testing
- Use golangci-lint for comprehensive linting
- Run tests on every pull request
- Include code coverage reporting
Related skills
entra-app-registrationmicrosoft606KGuides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.azure-messagingmicrosoft595KTroubleshoot and resolve issues with Azure Messaging SDKs for Event Hubs and Service Bus. Covers connection failures, authentication errors, message processing issues, and SDK configuration problems. WHEN: event hub SDK error, service bus SDK issue, messaging connection failure, AMQP error, event processor host issue, message lock lost, message lock expired, lock renewal, lock renewal batch, send timeout, receiver disconnected, SDK troubleshooting, azure messaging SDK, event hub consumer, servicentra-agent-idmicrosoft328KProvision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmi_path, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmi_path token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registsupabasesupabase298KUse when doing ANY task involving Supabase. Triggers: Supabase products (Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron, Queues); client libraries and SSR integrations (supabase-js, @supabase/ssr) in Next.js, React, SvelteKit, Astro, Remix; auth issues (login, logout, sessions, JWT, cookies, getSession, getUser, getClaims, RLS); Supabase CLI or MCP server; schema changes, migrations, declarative schemas, security audits, Postgres extensions (pg_graphql, pg_cron, pg_vector); deb