A powerful CLI tool to scaffold Go microservice projects with a predefined folder structure and production-ready templates.
- Quick Project Scaffolding: Generate complete Go microservice projects in seconds
- Production-Ready Templates: Includes Docker, Kubernetes, database migrations, and more
- Customizable Configuration: Flexible flags for database, Redis, ports, and environment settings
- Git Integration: Automatic Git repository initialization with dev branch
- Go Module Management: Automatic
go mod initandgo mod tidyexecution - Comprehensive Structure: Well-organized folder structure following Go best practices
- Hot Reload Support: Includes Air configuration for development
- API Documentation: Swagger/OpenAPI integration
- Observability: OpenTelemetry and Uptrace integration
- Database Migrations: Built-in migration support with golang-migrate
- Go 1.23.0 or higher
- Git (for repository initialization)
- Docker (optional, for containerization)
# One-liner installation (recommended)
curl -fsSL https://raw.githubusercontent.com/surahj/gomicrogen/main/install-oneline.sh | bash
# Or download and run the full installer
curl -fsSL https://raw.githubusercontent.com/surahj/gomicrogen/main/install.sh | bash# Run the PowerShell installer
Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/surahj/gomicrogen/main/install.ps1" -UseBasicParsing).ContentDownload the appropriate binary for your platform from the latest release:
# Download and extract the package
wget https://github.com/surahj/gomicrogen/releases/latest/download/gomicrogen-linux-amd64.tar.gz
tar -xzf gomicrogen-linux-amd64.tar.gz
# Install binary and templates
sudo cp gomicrogen-linux-amd64-package/gomicrogen-linux-amd64 /usr/local/bin/gomicrogen
sudo chmod +x /usr/local/bin/gomicrogen
sudo mkdir -p /usr/local/bin/templates
sudo cp -r gomicrogen-linux-amd64-package/templates/* /usr/local/bin/templates/# Download and extract the package
curl -L https://github.com/surahj/gomicrogen/releases/latest/download/gomicrogen-darwin-amd64.tar.gz | tar -xz
# Install binary and templates
sudo cp gomicrogen-darwin-amd64-package/gomicrogen-darwin-amd64 /usr/local/bin/gomicrogen
sudo chmod +x /usr/local/bin/gomicrogen
sudo mkdir -p /usr/local/bin/templates
sudo cp -r gomicrogen-darwin-amd64-package/templates/* /usr/local/bin/templates/# Download and extract from the latest release
# Then add the extracted directory to your PATH# Clone the repository
git clone https://github.com/surahj/gomicrogen.git
cd gomicrogen
# Build the binary
go build -o gomicrogen
# Make it executable
chmod +x gomicrogen
# Move to a directory in your PATH (optional)
sudo mv gomicrogen /usr/local/bin/go install github.com/surahj/gomicrogen@latest# Pull the latest image
docker pull ghcr.io/surahj/gomicrogen:latest
# Run gomicrogen
docker run --rm -it -v $(pwd):/workspace ghcr.io/surahj/gomicrogen:latest new my-service --module github.com/your-org/my-serviceCreate a new microservice with minimal configuration:
gomicrogen new my-service --module github.com/your-org/my-serviceThis will create a new microservice with:
- Complete project structure
- Docker configuration
- Kubernetes manifests
- Database migrations
- API documentation
- Hot reload setup
gomicrogen new [service-name] [flags]--module, -m: Go module name (e.g.,github.com/your-org/service-name)
--description, -d: Service description--version, -v: Service version (default: "1.0.0")--author, -a: Author name--port, -p: HTTP port (default: "8080")--grpc-port, -g: gRPC port (default: "8081")--env, -e: Environment (development, staging, production)
--db-driver: Database driver (mysql, postgres, sqlite)--db-url: Database connection URL--db-host: Database host (default: "localhost")--db-port: Database port (3306 for MySQL, 5432 for PostgreSQL)--db-password: Database password
--redis-url: Redis connection URL--redis-host: Redis host (default: "localhost")--redis-port: Redis port (default: "6379")--redis-db-number: Redis database number (0-15) (default: "0")--redis-password: Redis password
--output-dir, -o: Output directory (default: current directory)--force: Force overwrite if service already exists--git: Initialize Git repository with dev branch (default: true)--go-mod: Run go mod init and go mod tidy (default: true)
gomicrogen new user-service --module github.com/mycompany/user-servicegomicrogen new payment-service \
--module github.com/mycompany/payment-service \
--description "Payment processing microservice" \
--version "2.1.0" \
--author "John Doe" \
--port "3000" \
--grpc-port "3001" \
--db-driver "mysql" \
--db-host "localhost" \
--db-port "3306" \
--db-password "secret" \
--redis-host "localhost" \
--redis-port "6379" \
--env "development"gomicrogen new auth-service \
--module github.com/mycompany/auth-service \
--output-dir /path/to/projectsgomicrogen new my-service --module github.com/myorg/my-service --forcegomicrogen new my-service --module github.com/myorg/my-service --git=false --go-mod=false# General help
gomicrogen --help
# Command-specific help
gomicrogen new --help
# Show all available commands
gomicrogen helpservice-name/
βββ app/
β βββ auth/ # Authentication middleware
β βββ constants/ # Application constants
β βββ controllers/ # HTTP controllers
β βββ database/ # Database connection and models
β βββ grpc/ # gRPC server and services
β βββ library/ # Shared libraries and utilities
β βββ models/ # Data models
β βββ router/ # HTTP router setup
β βββ utils/ # Utility functions
βββ cmd/ # Command-line tools
βββ docs/ # API documentation
βββ k8s/ # Kubernetes manifests
βββ migrations/ # Database migrations
βββ test/ # Test files
βββ .gitignore # Git ignore file
βββ air.toml # Hot reload configuration
βββ docker-compose-local.yml # Local development setup
βββ Dockerfile # Production Docker image
βββ Dockerfile.dev # Development Docker image
βββ go.mod # Go module file
βββ go.sum # Go dependencies checksum
βββ main.go # Application entry point
βββ Makefile # Build and deployment commands
The generated service supports the following environment variables:
# Database Configuration
DATABASE_USERNAME=your_username
DATABASE_HOST=localhost
DATABASE_PORT=3306
DATABASE_PASSWORD=your_password
DATABASE_NAME=your_database
DATABASE_MAX_CONNECTION=150
DATABASE_IDLE_CONNECTION=100
DATABASE_CONNECTION_LIFETIME=60
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DATABASE_NUMBER=0
REDIS_PASSWORD=your_redis_password
# Service Configuration
SYSTEM_HOST=0.0.0.0
SYSTEM_PORT=8080
SYSTEM_GRPC_PORT=8081
ENV=development
# Observability
UPTRACE_DSN=your_uptrace_dsn
BASE_URL=https://your-api-domain.comFor local development, the generated service includes a docker-compose-local.yml file:
# Start the service locally
docker-compose -f docker-compose-local.yml up
# Build and start
docker-compose -f docker-compose-local.yml up --build-
Navigate to the project directory:
cd your-service-name -
Install dependencies:
go mod tidy
-
Set up environment variables:
cp .env.example .env # Edit .env with your configuration -
Run database migrations:
make migrate-up
-
Start the service:
# Development with hot reload make dev # Production make run # Or directly go run main.go
The generated service includes a comprehensive Makefile with useful commands:
# Development
make dev # Run with hot reload using Air
make run # Run the service
make build # Build the binary
make test # Run tests
make test-coverage # Run tests with coverage
# Database
make migrate-up # Run database migrations
make migrate-down # Rollback database migrations
make migrate-create # Create new migration
# Docker
make docker-build # Build Docker image
make docker-run # Run Docker container
make docker-stop # Stop Docker container
# Kubernetes
make k8s-deploy # Deploy to Kubernetes
make k8s-delete # Delete from Kubernetes
# Utilities
make clean # Clean build artifacts
make lint # Run linter
make fmt # Format codeThe generated service includes Swagger/OpenAPI documentation:
- Start the service
- Visit:
http://localhost:8080/swagger/index.html
The generated service includes:
- OpenTelemetry: Distributed tracing
- Uptrace: Metrics and monitoring
- Structured Logging: Using logrus
# Build development image
docker build -f Dockerfile.dev -t my-service:dev .
# Run with docker-compose
docker-compose -f docker-compose-local.yml up# Build production image
docker build -t my-service:latest .
# Run production container
docker run -p 8080:8080 -p 8081:8081 my-service:latestThe generated service includes Kubernetes manifests in the k8s/ directory:
# Deploy to Kubernetes
kubectl apply -f k8s/
# Check deployment status
kubectl get pods -l app=my-service- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
-
Installation fails
- Ensure you have write permissions to
/usr/local/bin/or use the one-line installer - Check that curl/wget is available on your system
- Verify your internet connection can access GitHub
- Ensure you have write permissions to
-
Go module initialization fails
- Check that Go is properly installed and in your PATH
- Ensure you have write permissions in the target directory
- Verify the module name follows Go module naming conventions
-
Database connection issues
- Verify database credentials and connection settings
- Ensure the database server is running and accessible
- Check that the database driver is supported (mysql, postgres, sqlite)
-
Port already in use
- Use different ports with
--portand--grpc-portflags - Check for existing services using the same ports
- Use
netstat -tulpn | grep :8080to check port usage
- Use different ports with
-
Git initialization fails
- Ensure Git is installed and configured
- Check that you have write permissions in the target directory
- Use
--git=falseto skip Git initialization if needed
- Create an issue on GitHub
- Check the existing issues for similar problems
- Review the generated code and configuration files
- Use
gomicrogen --helpfor command-line help
- Cobra - CLI framework for Go
- Air - Live reload for Go apps
- golang-migrate - Database migrations
- Uptrace - Observability platform