I'm creating this API just to learn more about GoLang and the Gin library. And i'm tryng to bring java concepts to GoLang like the way to organize code and files
- In the project root folder
-
docker-compose -f docker-compose.yml -p "Database_Containers" up -d
-
- In the Db_Postgres container you'll run ( You can access the container shell if you run this in your terminal: docker exec -it Db_Postgres /bin/bash )
-
psql -d Db_Gin -U root -h localhost -W
-
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; '( lets create the extension for UUID )'
-
CREATE TABLE tb_albums (id uuid DEFAULT uuid_generate_v4 (), title VARCHAR NOT NULL, artist VARCHAR NOT NULL, price float NOT NULL, PRIMARY KEY (id));
-
- In the project root folder
-
go run .
-
- In the test folder
-
go test -v
-
- GET - http://localhost:8080/albums ( Get all albums )
- GET - http://localhost:8080/albums/id ( Get an album by Id )
- POST - http://localhost:8080/albums ( Create a new album )
- PUT - http://localhost:8080/albums ( Update an existent album )
- DELETE - http://localhost:8080/albums/id ( Delete an album )
- Example Post request body
curl http://localhost:8080/albums \ --include --header "Content-Type: application/json" \ --request "POST" \ --data '{ \ "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", \ "title": "", \ "artist": "", \ "price": 00.00 \ }'
- Example PUT request body
curl http://localhost:8080/albums \ --include --header "Content-Type: application/json" \ --request "PUT" \ --data '{ \ "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", \ "title": "", \ "artist": "", \ "price": 00.00 \ }'