This is an implementation in Golang of a cart microservice extracted from a monolith migration. The current version is a work in progress and it is not fully completed.
/cart
endpoint.- API design
- Description of the architecture
- CORS
- Logging.
- Error recovery.
- Basic authentication: Currently, the list of users/passwords are hard coded.
- Database: The persistence layer is currently a SQLite database in memory with automatic migrations. It is good enough for development, but not for production.
/cart/{cartId}/item
endpoint.- Unit testing.
- Dockerfile.
- General polishing.
- Go 1.15
- SQLite 3.33.0
cd /cmd/cart
go mod download
go build
./cart
Unauthorised access
❯ http GET http://localhost:3000/cart
HTTP/1.1 401 Unauthorized
Access-Control-Allow-Methods: POST,GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH
Access-Control-Allow-Origin: *
Content-Length: 67
Content-Type: application/json; charset=utf-8
{
"description": "Unauthorised",
"error": "Unauthorised",
"description": "Unauthorised"
}
Create a cart
❯ http POST http://user:user@localhost:3000/cart
HTTP/1.1 201 Created
Access-Control-Allow-Methods: POST,GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH
Access-Control-Allow-Origin: *
Content-Length: 131
Content-Type: application/json; charset=utf-8
{
"created_at": "2020-09-05T21:51:38.9030783+02:00",
"id": 1,
"items": null,
"update_at": "2020-09-05T21:51:38.9030783+02:00",
"user_id": 2
}
Retrieve a cart
❯ http GET http://user:user@localhost:3000/cart/1
HTTP/1.1 200 OK
Access-Control-Allow-Methods: GET,GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH
Access-Control-Allow-Origin: *
Content-Length: 131
Content-Type: application/json; charset=utf-8
{
"created_at": "2020-09-05T21:51:38.9030783+02:00",
"id": 1,
"items": null,
"update_at": "2020-09-05T21:51:38.9030783+02:00",
"user_id": 2
}