Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-starter 🚀

A professional CLI tool that scaffolds production-ready Go REST API projects in seconds.


✨ Features

Feature Description
🗄️ Multi-database MySQL, PostgreSQL, SQLite — choose during setup
🎨 Interactive TUI Beautiful survey wizard powered by AlecAivazis/survey
🔐 JWT Auth Optional hand-rolled JWT middleware (jwt.MapClaims, HS256) with built-in RBAC via AuthMiddleware(roles ...string)
🍪 Session Auth Optional cookie-session auth (gofiber/session) — same register/login/profile endpoints
🧪 Tests included Unit tests (requests, password, JWT) + full register→login→profile integration test
📋 Zerolog Logger Structured JSON logging with pretty dev console
🐳 Docker Multi-stage Dockerfile + docker-compose with DB health checks
🛠️ Makefile run, build, test, lint, docker-up, migrate targets
📖 README Auto-generated README with project structure & commands
🌿 Git Init Optional git repository initialization
♻️ Graceful Shutdown OS signal handling for clean server shutdown
🏥 Health Check /health endpoint with uptime & runtime metrics

📦 Installation

git clone https://github.com/ehanz12/go-starter
cd go-starter
go build -o go-starter .

Or install directly:

go install github.com/ehanz12/go-starter@latest

🚀 Usage

Interactive wizard (recommended)

go-starter new my-api

This launches a TUI where you select:

  • Module name
  • Database driver (MySQL / PostgreSQL / SQLite)
  • Optional features (JWT / Session auth, Docker, Logger, Makefile, README)
  • Whether to initialise a Git repository

With flags (skip wizard questions)

# Specify database driver upfront
go-starter new my-api --db postgres

# Full example with all flags
go-starter new my-api \
  --module github.com/yourusername/my-api \
  --db postgres \
  --git

List available databases & features

go-starter list

📁 Generated Project Structure

my-api/
├── cmd/api/          # Application entry point (main.go)
├── config/           # Config struct loaded from .env
├── database/         # DB connection + migrations folder
├── internal/
│   ├── handlers/     # HTTP handlers (Welcome + HealthCheck)
│   ├── middleware/   # JWT auth (hand-rolled + RBAC), Logger (if selected)
│   ├── models/       # GORM models
│   ├── repositories/ # Data access layer
│   ├── requests/     # Request DTOs / input structs
│   ├── responses/    # Response DTOs
│   ├── routes/       # Route registration + error handler
│   ├── services/     # Business logic layer
│   ├── utils/        # Shared helpers
│   └── validators/   # Input validation
├── docs/             # Swagger / API documentation
├── logs/             # Log files (git-ignored)
├── storage/          # Uploaded files (git-ignored)
├── scripts/          # DB seed scripts
├── pkg/              # Reusable packages
├── Dockerfile        # (if Docker selected)
├── docker-compose.yml # (if Docker selected)
├── Makefile          # (if Makefile selected)
├── README.md         # (if README selected)
├── .env              # Environment variables
└── .env.example      # Environment template (safe to commit)

🔐 JWT Auth (generated project)

When JWT Auth is selected, the generated project ships with register/login/profile and a hand-rolled JWT middleware (same style as a typical Fiber + golang-jwt/jwt setup):

  • Token: HS256 with jwt.MapClaims — user_id, role, exp (expiry from JWT_EXPIRY_HOURS in .env)
  • Protect a route — any authenticated user:
    protected := api.Group("/", middleware.AuthMiddleware())
  • RBAC — restrict to specific roles (valid token but wrong role → 403):
    admin := api.Group("/admin", middleware.AuthMiddleware("admin", "superadmin"))
  • In handlers read the authenticated user via middleware.GetUserID(c) / middleware.GetRole(c)

🛠️ CLI Reference

go-starter [command]

Commands:
  new     Create a new Go project (interactive wizard)
  list    List available databases and optional features

Flags for `new`:
  -m, --module   Module name (default: github.com/yourusername/<name>)
  -d, --db       Database driver: mysql | postgres | sqlite
      --git      Initialize a Git repository

🤝 Contributing

PRs welcome! Please open an issue first to discuss what you'd like to change.


📄 License

MIT © ehanz12

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages