A production-ready Go project template with best practices, standardized structure, and modern development tooling.
- Modern Go Structure: Follows the Standard Go Project Layout
- Docker Support: Multi-stage Dockerfile for optimized production builds
- Dev Container: Pre-configured development environment with VS Code integration
- CI/CD Ready: GitHub Actions workflows and conventional commit guidelines
- Extensible Architecture: Pre-structured packages for common requirements:
- Database connectivity (
pkg/database/) - Message queue integration (
pkg/queue/) - HTTP routing and middleware (
internal/router/) - Audit logging and tracing (
internal/)
- Database connectivity (
.
βββ cmd/ # Main applications for this project
βββ internal/ # Private application and library code
β βββ audit.go # Audit logging functionality
β βββ tracing.go # Distributed tracing support
β βββ router/ # HTTP server and middleware
β βββ server.go
β βββ middleware.go
βββ pkg/ # Public library code (safe to import)
β βββ database/ # Database clients and connections
β β βββ mongodb.go
β βββ queue/ # Message queue integrations
β βββ rabbitmq.go
βββ example/ # Example applications and documentation
βββ .devcontainer/ # VS Code dev container configuration
βββ .github/ # GitHub workflows and templates
βββ Dockerfile # Multi-stage production build
βββ go.mod # Go module definition
βββ main.go # Application entry point
- Go 1.24+ (or use the provided dev container)
- Docker (optional, for containerized development)
-
Create a new repository from this template:
- Click "Use this template" on GitHub
- Or clone directly:
git clone https://github.com/uug-ai/templates-go.git your-project
-
Update module name:
# Replace the module path in go.mod go mod edit -module github.com/yourusername/yourproject -
Install dependencies:
go mod download
-
Run the application:
go run main.go
This template includes a complete dev container configuration:
- Open the project in VS Code
- Install the "Dev Containers" extension
- Click "Reopen in Container" when prompted
- All tools and dependencies are automatically configured
# Build for your current platform
go build -o app main.go
# Build with optimizations
go build -ldflags="-s -w" -o app main.go# Build the Docker image
docker build \
--build-arg project=myapp \
--build-arg github_username=your-username \
--build-arg github_token=your-token \
-t myapp:latest .
# Run the container
docker run -p 8080:8080 myapp:latestPrivate application code that should not be imported by other projects:
audit.go: Audit logging and compliance trackingtracing.go: OpenTelemetry or similar tracing integrationrouter/: HTTP server setup and middleware stack
Public packages that can be imported by external projects:
database/: Database connection management (MongoDB, PostgreSQL, etc.)queue/: Message queue clients (RabbitMQ, Kafka, etc.)
Entry points for different applications (CLIs, services, workers):
cmd/
βββ server/ # Main HTTP server
βββ worker/ # Background job processor
βββ migrate/ # Database migration tool
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run tests with verbose output
go test -v ./...The template supports environment-based configuration:
-
Copy
.envto.env.local:cp .env .env.local
-
Update
.env.localwith your local settings (this file is gitignored) -
Common environment variables:
# Application APP_NAME=myapp APP_ENV=development PORT=8080 # Database MONGODB_URI=mongodb://localhost:27017 DATABASE_NAME=myapp # Message Queue RABBITMQ_URL=amqp://guest:guest@localhost:5672/
This project follows Conventional Commits:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore
Examples:
feat(api): add user authentication endpoint
fix(database): resolve connection pooling issue
docs(readme): update installation instructions
See .github/copilot-instructions.md for detailed guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feat/amazing-feature - Commit your changes:
git commit -m 'feat: add amazing feature' - Push to the branch:
git push origin feat/amazing-feature - Open a Pull Request
This template is available as open source. Modify and use it for your projects.
- Go Documentation
- Standard Go Project Layout
- Effective Go
- Conventional Commits
- Spec Kit β Spec-Driven Development
This template ships with Spec Kit pre-installed in the dev container. Spec Kit lets you focus on what to build before how β specifications become the source of truth that drives AI-assisted implementation.
The specify CLI is already on your PATH inside the dev container.
# Verify the installation
specify check
# Initialize Spec Kit in this project (using GitHub Copilot)
specify init --here --ai copilot --ignore-agent-tools
# Or with another supported AI agent
specify init --here --ai claude --ignore-agent-toolsNote: Use
--ignore-agent-toolsinside the dev container to skip checks for agent CLI tools (e.g. Claude Code, Copilot CLI) that run on the host machine.
Once initialized, use the slash commands from your AI coding agent:
| Step | Command | Purpose |
|---|---|---|
| 1 | /speckit.constitution |
Define project principles and quality guidelines |
| 2 | /speckit.specify |
Describe what you want to build (the what, not the how) |
| 3 | /speckit.plan |
Create a technical implementation plan with your Go stack |
| 4 | /speckit.tasks |
Break the plan into actionable tasks |
| 5 | /speckit.implement |
Execute all tasks to build the feature |
# 1. Initialize Spec Kit
specify init --here --ai copilot --ignore-agent-tools
# 2. Open your AI agent and run:
# /speckit.constitution Focus on idiomatic Go, table-driven tests, and clean package boundaries
# /speckit.specify Build a REST API that exposes CRUD operations for a "projects" resource
# /speckit.plan Use net/http, MongoDB for persistence, and the existing pkg/database package
# /speckit.tasks
# /speckit.implementFor the full methodology see the Spec-Driven Development guide.
- Keep
internal/for code specific to your application - Put reusable libraries in
pkg/if you plan to share them - Use
cmd/for multiple binaries (services, CLI tools, etc.) - Leverage the dev container for consistent development environments
- Follow the commit conventions for better changelog generation
Built with β€οΈ by UUG.AI