Skip to content

mrahmanashiq/gogen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ GoGen - Go Project Template Generator

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.

Go Version License

✨ Features

  • 🎯 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

πŸ“¦ Installation

Option 1: Download Binary

# 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/

Option 2: Build from Source

git clone https://github.com/username/gogen.git
cd gogen
go build -o bin/gogen .

Option 3: Install with Go

go install github.com/username/gogen@latest

πŸš€ Quick Start

Interactive Mode (Recommended)

gogen generate

Non-Interactive Mode

# 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

πŸ“‹ Available Templates

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

View All Templates

gogen list

🎯 Usage Examples

1. Create a Web Service

gogen generate my-api --template web --interactive=false
cd my-api
go mod tidy
go run main.go

The web service will start on port 8080 with endpoints:

  • GET /health - Health check
  • GET /api/v1/hello - Hello world
  • GET /api/v1/users - List users
  • POST /api/v1/users - Create user

2. Create a CLI Application

gogen generate my-tool --template cli
cd my-tool
go build -o bin/my-tool
./bin/my-tool hello --name "World"

3. Create a Library

gogen generate my-lib --template library
cd my-lib
go test ./...
go run examples/basic/main.go

4. Create a Microservice

gogen generate my-service --template microservice
cd my-service
docker-compose up --build

Access:

5. Create a gRPC Service

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 client

βš™οΈ Configuration Options

When 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

πŸ—οΈ Generated Project Structure

Web Service

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

CLI Application

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

πŸ”§ Development

Building GoGen

# 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 ./...

Adding New Templates

  1. Create a new template file in internal/templates/
  2. Implement the GetXXXTemplate() function
  3. Register it in internal/templates/registry.go
  4. 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
        },
    }
}

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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

πŸ“ž Support


Made with ❀️ for the Go community

About

modern CLI tool for generating Go project templates with best practices

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published