README
ΒΆ
Go Project Template
A production-ready Go project template with best practices, standardized structure, and modern development tooling.
π Features
- 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 (
π Project Structure
.
βββ 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
π οΈ Getting Started
Prerequisites
- Go 1.24+ (or use the provided dev container)
- Docker (optional, for containerized development)
Using This Template
-
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
Development with Dev Container
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
ποΈ Building
Local Build
# Build for your current platform
go build -o app main.go
# Build with optimizations
go build -ldflags="-s -w" -o app main.go
Docker Build
# 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:latest
π¦ Package Overview
internal/
Private 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
pkg/
Public packages that can be imported by external projects:
database/: Database connection management (MongoDB, PostgreSQL, etc.)queue/: Message queue clients (RabbitMQ, Kafka, etc.)
cmd/
Entry points for different applications (CLIs, services, workers):
cmd/
βββ server/ # Main HTTP server
βββ worker/ # Background job processor
βββ migrate/ # Database migration tool
π§ͺ Testing
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run tests with verbose output
go test -v ./...
π§ Configuration
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/
π Commit Guidelines
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.
π€ Contributing
- 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
π License
This template is available as open source. Modify and use it for your projects.
π Resources
π‘ Tips
- 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
Documentation
ΒΆ
There is no documentation for this package.