A Simple Monolithic Golang API built with Gorilla/Mux and PostgreSQL, to enhance my Golang Knowledge, documented with swagger.
Download this project:
git clone https://github.com/Philipelima/go-books-api.git
Execute go mod tidy to download the required dependencies:
go mod tidyTo run the PostgreSQL DB, please run the following command:
docker compose upThe database migrations are handled using the migrate package. You can learn more about it on Golang Migrate.
You’ll find all migration files in cmd/migrate/migrations.
After configuring the migrate package on your machine, you can run:
make migrate-upIf you need to roll back the migrations, run:
make migrate-downIf you want to add a new migration to the project:
make migration {migration_name}It’s possible to run database seeds in this project.
You can find the seed script in cmd/seed.
To use it, simply create a {entity}.json file inside cmd/seed/data, following the payload structure, and then implement the EntitySeed interface in the entity you want to use for populating the database.
After that, just run:
go run cmd/seed/main.go seed:{json_file_name}After all configurations done, just run:
make devTo See the swagger docs, access http://127.0.0.1:8000/swagger/index.html#/
