Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tompston/gomakeme
Generate boilerplate + endpoints for Fiber or Gin REST APIs.
https://github.com/tompston/gomakeme
api boilerplate go go-fiber go-gin rest rest-api
Last synced: 26 days ago
JSON representation
Generate boilerplate + endpoints for Fiber or Gin REST APIs.
- Host: GitHub
- URL: https://github.com/tompston/gomakeme
- Owner: tompston
- License: mit
- Created: 2021-11-08T18:06:38.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-21T19:59:57.000Z (over 2 years ago)
- Last Synced: 2024-10-02T09:14:18.309Z (about 1 month ago)
- Topics: api, boilerplate, go, go-fiber, go-gin, rest, rest-api
- Language: Go
- Homepage:
- Size: 2.08 MB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fiber - tompston/gomakeme - Generate boilerplate + endpoints for Fiber or Gin REST APIs. (🛠️ Tools / 🌱 Third Party)
README
# gomakeme
Generate boilerplate + endpoints for Fiber or Gin REST APIs.
#### Table of contents
- [Install](#install)
- [Generate the REST API](#generate-the-rest-api)
- [Explanation](#explanation)
- [Config file](#config-file)
- [Notes](#notes)## Install
```bash
# go version >= 1.17
go install github.com/tompston/gomakeme@latest# go version < 1.17
go get github.com/tompston/gomakeme# or clone the repo and run go run main.go
git clone https://github.com/tompston/gomakeme.git
```## Generate the REST API
1. Create the `gomakeme.yml` config file, copy example settings from this repo and update values
2. run `gomakeme` in the directory which holds the yaml config
3. cd into the created project and run```bash
go mod tidy
go mod download
gofmt -s -w .
go run main.go
# + change the .env vars
```
Once generated, only the "router/project_modules.go" file will be updated on the next gomakeme runs. All of the other files won't be touched## Explanation
It seems like one of the boring / repetitive parts of writing basic REST APIs is the boilerpate for the endpoints.
Want to add a new table to the database and create endpoints for it? Before starting to do so, you need to write the new routes and controllers that deal with the common CRUD opetations.
Want to add another table? Repat the same process again, but change only the name to the new table.
So this stuff is boring and repetative. That's why you can automate it.
## Config file
**Commented out lines + modules lines are optional**
**All of the other lines are mandatory!**Currently there are three main options for the project that you could generate:
1. Minimal server with no endpoints
2. Server that uses modules
3. Server that uses modules + additional boilerplate for SQLC_\* examples of all options can be found inside examples dir_
The option you choose is based on the `gomakeme.yml` config file. If there are modules specified in the config file, they will be added to the project.
For example, if your config file has some defined modules, like
```yml
modules: [User, Task]
```The `user_module` will be created in the `modules` directory.
#### sqlc: true
If true, then sqlc config files and sql files for modules will also be generated inside `/db` dir. The sql files that would be used by sqlc would include
- table with the name of the module + 3 frequently used columns (id, created_at, updated_at)
- 5 CRUD queries with placeholder valuesAdditionaly a functions.sql file will be created that will hold a function that will be triggered once the db row is updated.
No migration tools included, SQLC documentation lists some possible [options](https://docs.sqlc.dev/en/latest/howto/ddl.html?highlight=migr#handling-sql-migrations) that could be used, so check them out and pick one that you like the most.
#### include_db_snippet: true
If true, includes a snippet inside the controllers that can create a connection to the database
#### Adding new modules
On each run the program checks if the module specified in the config file exists in the `project_name/modules/` dir. If a new module is added in the modules array, it will be added to the generated server.
### Module
A single module will hold 5 basic CRUD endpoints that will be automatically available to the server. The generated controllers are held in seperate files, where the name of the file indicates what type of http request is associated with it. The controllers can also hold common functions, such as
- validation of url params, if there are any
- validation and custom error messages for the sent payloads
- database connection ( if set to true in the config file )Once the directory for the `user_module` is created, it won't be updated if you run the `gomakeme` again, so you can edit them.
## Notes
- Taking a bit of inspiration from Nest.js, we bundle router + controllers into one package.
- There are probably bugs. Somewhere