gon
Scaffold models, usecases, and handlers for Go apps with an opinionated directory layout — just like Rails, but for Go.
✨ Rails-like Developer Experience
Inspired by the Rails philosophy of convention over configuration, gon lets you scaffold everything you need for a domain entity — model, repository, usecase, and handler — with a single command.
gon g scaffold User name:string email:string
This generates fully structured code under internal/domain/user/, just like rails g scaffold — but in idiomatic Go.
✨ Features
- Rails-style generators for Go projects
- Generate boilerplate code for Clean Architecture
- Support for models, repositories, usecases, and handlers
- Enforces consistent directory structure
- Lightweight and fast CLI
🚀 Installation
Go 1.17 or later
go install github.com/mickamy/gon@latest
Make sure $GOPATH/bin is in your $PATH.
Go 1.24 or later (with go get -tool)
go get -tool github.com/mickamy/gon
This installs gon to $GOTOOLDIR/bin (usually $HOME/go/bin).
📦 Initial Setup
Step 1: Create configuration file
This creates a gon.yaml file with default settings. You can tweak output paths, package names, and template locations.
Step 2: Install templates and dependencies
This command generates the database file and prepares templates required for scaffolding, including:
- Embedded templates for model, repository, usecase, handler
- Includes lightweight test helpers like
httptestutil/request.go, generated during install for better testing experience.
💡 Make sure to run this before using
gon gorgon d.
🧪 Usage
Generate a domain model
gon generate model User name:string email:string
# or simply
gon g model User name:string email:stringGenerate a usecase
Generate a handler
gon g handler User list create
Scaffold everything
gon g scaffold User name:string email:string
This generates model, repository, usecase, handler, and fixture in one shot.
Destroy everything
This deletes generated files for the given domain entity.
📁 Output Structure
internal/
└── domain/
└── user/
└── fixture/
│ └── user_fixture.go
├── model/
│ └── user_model.go
├── usecase/
│ ├── create_user_use_case.go
│ ├── get_user_use_case.go
│ ├── list_user_use_case.go
│ ├── update_user_use_case.go
│ └── delete_user_use_case.go
├── repository/
│ └── user_repository.go
└── handler/
└── user_handler.go
test/
└── httptestutil/
└── request.go
Each subdirectory under
domain/{name}is a separate package.
🧪 Testing & Fixtures
When generating code, gon also prepares test helpers to improve DX:
httptestutil.RequestBuilderto build and test Echo requests- Zero-value based fixtures with
TODOcomments for easy customization
package fixture func User(setter func(*model.User)) model.User { m := model.User{ // TODO: fill in default values } if setter != nil { setter(&m) } return m }
🛠 Template Driven
Templates are embedded using Go 1.16+ embed package. You can customize them by copying from the embedded defaults
during gon install.
📚 Example Project
You can find a working example project using gon under the example/ directory.
This example demonstrates how the generated code looks and how to structure your application using gon's opinionated layout. It’s a great starting point to explore and adapt into your own Go project.