GoGen is a powerful and modern CLI tool for generating Go project templates with best practices, common tools, and proper project structure. It helps developers quickly scaffold new Go projects with industry-standard configurations.
- π― Multiple Project Templates - Web services, CLI apps, libraries, microservices, and gRPC services
- π¨ Interactive Wizard - Guided project setup with customizable options
- ποΈ Best Practices - Industry-standard project structure and tooling
- π³ Docker Ready - Optional Docker and Docker Compose configurations
- βοΈ CI/CD Included - GitHub Actions workflows for testing and deployment
- π¦ Common Tools - Makefile, linting, formatting, and more
- π Beautiful CLI - Colorful and intuitive command-line interface
# Download the latest release (replace with your preferred version)
curl -L https://github.com/username/gogen/releases/latest/download/gogen-linux-amd64 -o gogen
chmod +x gogen
sudo mv gogen /usr/local/bin/git clone https://github.com/username/gogen.git
cd gogen
go build -o bin/gogen .go install github.com/username/gogen@latestgogen generate# Generate a web service
gogen generate my-api --template web
# Generate a CLI application
gogen generate my-tool --template cli
# Generate a library
gogen generate my-lib --template library| Template | Description | Features |
|---|---|---|
| web | RESTful web service | Gin framework, middleware, API endpoints, health checks |
| cli | Command-line application | Cobra CLI, subcommands, configuration management |
| library | Go library/package | Public API, comprehensive tests, examples, documentation |
| microservice | Production microservice | Docker, health checks, metrics, structured logging |
| grpc | gRPC service | Protocol Buffers, client stubs, interceptors |
gogen listgogen generate my-api --template web --interactive=false
cd my-api
go mod tidy
go run main.goThe web service will start on port 8080 with endpoints:
GET /health- Health checkGET /api/v1/hello- Hello worldGET /api/v1/users- List usersPOST /api/v1/users- Create user
gogen generate my-tool --template cli
cd my-tool
go build -o bin/my-tool
./bin/my-tool hello --name "World"gogen generate my-lib --template library
cd my-lib
go test ./...
go run examples/basic/main.gogogen generate my-service --template microservice
cd my-service
docker-compose up --buildAccess:
- Service: http://localhost:8080
- Metrics: http://localhost:9090/metrics
- Grafana: http://localhost:3000 (admin/admin)
gogen generate my-grpc --template grpc
cd my-grpc
make proto # Generate protobuf files
go run main.go # Start server
go run cmd/client/main.go # Test clientWhen using interactive mode, you can configure:
- Project Name - The name of your project
- Module Prefix - Go module prefix (e.g., github.com/username)
- Description - Project description
- Docker Support - Include Dockerfile and docker-compose.yml
- GitHub Actions - Include CI/CD workflows
- Makefile - Include build automation
my-api/
βββ main.go # Application entry point
βββ internal/
β βββ api/ # API layer
β β βββ handlers/ # HTTP handlers
β β βββ middleware/ # HTTP middleware
β β βββ server.go # Server setup
β βββ config/ # Configuration
βββ .env.example # Environment template
βββ Dockerfile # Docker configuration
βββ Makefile # Build automation
βββ .github/workflows/ # CI/CD pipelines
βββ README.md # Documentation
my-tool/
βββ main.go # Application entry point
βββ cmd/ # Command definitions
β βββ root.go # Root command
β βββ version.go # Version command
β βββ hello.go # Example command
βββ Makefile # Build automation
βββ README.md # Documentation
# Build for current platform
go build -o bin/gogen .
# Build for multiple platforms
make build-all
# Run tests
go test ./...
# Run with coverage
go test -cover ./...- Create a new template file in
internal/templates/ - Implement the
GetXXXTemplate()function - Register it in
internal/templates/registry.go - Add it to the available templates list
Example:
func GetMyTemplate() *Template {
return &Template{
Name: "My Template",
Type: "my-template",
Description: "Description of my template",
Features: []string{"feature1", "feature2"},
Files: []TemplateFile{
// Template files here
},
}
}We welcome contributions! Please see our Contributing Guide for details.
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
- Cobra - For the excellent CLI framework
- Survey - For interactive prompts
- Gin - For the web framework used in templates
- All the amazing Go community for inspiration and best practices
- π§ Email: [email protected]
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
Made with β€οΈ for the Go community