Gomancer is a powerful code generator designed to make API development in Go REALLY fast! It automates the creation of models, controllers, repositories, and database migrations, allowing you to focus on your business logic rather than boilerplate code.
Inspired by tools like Phoenix's generators in Elixir, Gomancer brings rapid API development to the Go ecosystem by leveraging existing powerful packages and organizing them in a cohesive way.
Create a new project:
gomancer new github.com/user/great_api
cd great_api
go mod tidy
npm i # for Prisma dependenciesGenerate a complete API resource:
gomancer gen User name:string age:int8 dob:time:optional --pk-uuidAnd just like that, you're ready to go with a fully functional API!
go install github.com/manicar2093/gomancer@latestGomancer creates a well-structured project with:
- Echo web framework configuration
- Prisma for database migrations
- GORM for database access
- Templ for SSR (Server Side Rendering)
- TemplUI for html components
- Environment configuration
- GitHub workflow (bump_version) for automatic semantic versioning and changelog generation
- Air for hot reloading
- And more!
Generate complete API resources with a single command:
- Models with validation
- Controllers with CRUD endpoints
- Repositories with database operations
- Database migrations
Gomancer supports a wide range of data types:
- Basic types: int, int8, int16, int32, int64, float32, float64, string, bool
- Complex types: time, decimal, uuid
- Enums (with custom values)
- Optional fields
- Auto-increment integer (default)
- UUID (with
--pk-uuidflag)
gomancer new github.com/username/awesome-apiAll resources will generate Web and Rest controllers
Basic resource with auto-increment ID:
gomancer gen Client name:string email:string age:intResource with UUID primary key:
gomancer gen Product name:string price:decimal stock:int --pk-uuidResource with optional fields:
gomancer gen User name:string bio:string:optional avatar:string:optionalResource with enum field:
gomancer gen Order status:enum/pending/processing/shipped/delivered total:decimalWhen you create a new project with Gomancer, it generates the following structure:
<project_name>/
├── .github
│ └── workflows
├── cmd
│ ├── service
│ │ ├── assets
│ │ │ ├── css
│ │ │ ├── img
│ │ │ └── js
│ │ ├── controllers
│ │ │ ├── initpages
│ │ │ ├── init_rest.go
│ │ │ └── init_web.go
│ │ ├── sources
│ │ │ └── css
│ │ ├── translations
│ │ │ ├── en
│ │ │ ├── es
│ │ │ └── translations.go
│ │ └── main.go
├── core
│ ├── apperrors
│ ├── commonreq
│ ├── connections
│ ├── converters
│ ├── echoer
│ ├── env
│ ├── httphealthcheck
│ ├── logger
│ ├── stages
│ ├── validator
│ ├── web
│ ├── config.go
│ ├── controllers.go
│ ├── ctx_utils.go
│ ├── flash.go
│ ├── middlewares.go
│ ├── templctx.go
│ └── templrender.go
├── internal
│ └── domain
├── pkg
│ ├── config
│ ├── generators
│ ├── testfunc
│ └── versioning
├── prisma
│ └── schema
├── .air.toml
├── .cz.toml
├── .env
├── .env.test
├── go.mod
├── Makefile
├── package.json
├── project_struct.txt
├── README.md
└── Taskfile.yml
I started with the following question:
Do we really need a fullstack framework for Golang?
I think Go has many powerful packages to handle projects of all sizes, but there was no way to create APIs quickly and efficiently.
Once I tried to learn Elixir and Phoenix, I was shocked by the phx.gen tool. You can get a usable API in milliseconds, even create CRUDs with just a CLI command. Why not bring this to Go?
We have everything: ORMs, HTTP Servers, UI Libraries, Validation packages...EVERYTHING! We just need to gather them all in one place, ready to be used.
That's why Gomancer was born.
Now the only thing to notice is all dates are handled as UTC and show as Local when data is shown in a HTML input :/. There is an issue #27 to review this.
- Start a project
- Create controller
- Create controller testing
- Create models
- Create migrations with Prisma
- Create CRUD repository
- Create CRUD testing
- Create all at once: controller, model, migration and repository
- Create API documentation
- Create auth implementation
- Add CRUD HTML templates
- Add CRUD HTML testing
-
Add API testing: Removed due controller testing covers this
- On PartialUpdateById test bool and enums (and it optional variations) has no random validations. This is due bool just has 2 possible values and enums can have from 1 to many. This makes it hard to randomize tests.
- On command when writing an attribute called data_32 snake case is not well converted. This can cause problems with Gorm ORM due gorm will transform it to data32 and model will be data_32. Horrible, but avoidable if not use _ in attributes declaration
- For controller testing: apitest
- For API documentation: To be defined. I'm thinking about swag
- For CRUD HTML: apitest with goquery
Feel free to suggest any other tool to use :D
This project is licensed under the MIT License - see the LICENSE file for details.