Go REST API - Bucket list - built with go-chi, Docker, and PostgreSQL
Requirements
- Docker and Go
- golang-migrate/migrate
Usage
Clone the repository with:
git clone github.com/zurcacielos/bucketeer
Copy the env.example
file to a .env
file.
$ cp .env.example .env
Update the postgres variables declared in the new .env
to match your preference. There's a handy guide on the Postgres' DockerHub.
Build and start the services with:
$ docker-compose up --build
Test
###POST
curl -X POST http://localhost:8080/items -H "Content-type: application/json" -d '{ "name": "swim across the River Benue", "description": "ho ho ho"}'
curl -X POST http://localhost:8080/items -H "Content-type: application/json" -d '{ "name": "read all the books in the world", "description": "get an ebook reader"}'
###GET
curl http://localhost:8080/items/1
The database migration files are in db/migrations
and will be run by composer up. Beside that feel free to simply source them directly. Alternatively, you can apply them using migrate
by running:
$ export POSTGRESQL_URL="postgres://$PG_USER:$PG_PASS@localhost:5432/$PG_DB?sslmode=disable"
$ migrate -database ${POSTGRESQL_URL} -path db/migrations up
NOTE: Remember to replace the $PG*
variables with their actual values
Development
After making your changes, you can rebuild the server
service by running the commands below
$ docker-compose stop server
$ docker-compose build server
$ docker-compose up --no-start server
$ docker-compose start server