tuan-cli
v1.0.2
Published
A CLI tool for generating Golang service templates
Maintainers
Readme
Tuan CLI
A powerful CLI tool for generating Golang service templates with support for microservices architecture.
Features
- Initialize Golang project structure
- Generate microservice templates with proper Go modules
- Docker support for containerization
- Cross-platform support (Windows, macOS, Linux)
- Interactive prompts for project configuration
Installation
Global Installation
npm install -g tuan-cliLocal Installation
npm install tuan-cliUsage
Initialize a new project
# Initialize with project name
tuan init MyProject
# Initialize with version
tuan init MyProject --version 2.0.0
# Interactive initialization (will prompt for project name)
tuan initThis creates the following structure:
MyProject/
├── clients/ # Client files
├── docker/ # Docker configurations
├── pkgs/
│ └── gopkg/ # Go packages
├── protoc/
│ └── protogo/
│ └── go.mod # Protocol buffers go.mod
├── services/ # Microservices directory
└── tuan.json # Project configurationCreate a microservice
tuan mirsrv UserServiceThis creates a microservice with the following structure:
services/UserService/
├── apis/ # API handlers
├── daos/ # Data access objects
├── cmd/
│ ├── service/
│ │ └── main.go # Main service file
│ └── scripts/
│ └── install_test.go # Database installation test
├── go.mod # Go module file
└── Dockerfile # Docker configurationConfiguration File
The tuan.json file stores project configuration:
{
"project_name": "MyProject",
"version": "1.0.0"
}Generated Templates
Main Service Template
The generated main.go includes:
- CORS middleware
- gRPC panic handling
- Sunny framework integration
- Environment and configuration flags
Go Module Template
The generated go.mod includes:
- Required dependencies (Gin, Sunny, Logrus, gRPC, GORM)
- Local package replacements
- Proper module structure
Docker Template
Multi-stage Dockerfile for optimized builds:
- Builder stage with Golang Alpine
- Final stage with minimal Alpine
- Security certificates and timezone data
Cross-Platform Support
Tuan CLI supports:
- Windows: Command Prompt and PowerShell
- macOS: Terminal and iTerm2
- Linux: All major distributions
Development
Build
npm run buildDevelopment Mode
npm run devRun Tests
npm testClean Build
npm run cleanPublishing to NPM
# Build and publish
npm run pub
# Or manually
npm run build
npm publishRequirements
- Node.js >= 16.0.0
- npm >= 7.0.0
License
MIT
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Examples
Complete Project Setup
# Initialize new project
tuan init ECommerceApp
# Create microservices
tuan mirsrv UserService
tuan mirsrv OrderService
tuan mirsrv ProductService
# Navigate to a service
cd services/UserService
# Install dependencies
go mod tidy
# Run tests
go test ./cmd/scripts/
# Start the service
go run cmd/service/main.goDocker Build
# Build Docker image
cd services/UserService
docker build -t user-service .
# Run container
docker run -p 8080:8080 user-service