Scaffold models, usecases, and handlers for Go apps with an opinionated directory layout — just like Rails, but for Go.
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:stringThis generates fully structured code under internal/domain/user/, just like rails g scaffold — but in idiomatic Go.
- 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
go install github.com/mickamy/gon@latestMake sure $GOPATH/bin is in your $PATH.
go get -tool github.com/mickamy/gonThis installs gon to $GOTOOLDIR/bin (usually $HOME/go/bin).
gon initThis creates a gon.yaml file with default settings. You can tweak output paths, package names, and template locations.
gon installThis 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.
gon generate model User name:string email:string
# or simply
gon g model User name:string email:stringgon g usecase CreateUsergon g handler User list creategon g scaffold User name:string email:stringThis generates model, repository, usecase, handler, and fixture in one shot.
gon d scaffold UserThis deletes generated files for the given domain entity.
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.
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
}Templates are embedded using Go 1.16+ embed package. You can customize them by copying from the embedded defaults
during gon install.
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.