Generate boilerplate + endpoints for Fiber or Gin REST APIs.
# 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
gomakeme.yml
config file, copy example settings from this repo and update valuesgomakeme
in the directory which holds the yaml configgo mod tidy
go mod download
gofmt -s -w .
go run main.go
# + change the .env vars
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.
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:
* 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
modules: [User, Task]
The user_module
will be created in the modules
directory.
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
Additionaly 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 that could be used, so check them out and pick one that you like the most.
If true, includes a snippet inside the controllers that can create a connection to the database
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.
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
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.