This is a simple classified-ads microservice in Go.
- A way to insert a new ad. An ad consists of a subject, a body, an optional price, and an email address.
- A way of fetching existing ads. It should be possible to sort the ads on the time they were inserted and by their price.
- A way of deleting a previously inserted ad.
The service needs Mysql to run successfully. Let's use docker-compose to run those servers.
docker-compose up -d mysqlAnd now you can build and run the server:
go run main.goTo run as a service we can create an image and use docker-compose to start the containers. First the image:
docker build . -t service:latestPS: Docker file uses revive (go lint successor) and gosec tools to validate code written in the solution is following some standard go best practices.
Now we can run all the servers together using docker-compose.
docker-compose upPOST http://localhost:8000/api/ads
{ "email": "test@test.com", "subject": "random-subject", "price": 100.00, "body": "random-body" }
http://localhost:8000/api/ads?sortBy={created_at, price}&orderBy={asc, desc}
http://localhost:8000/api/ads/{id}
Again with docker-compose:
docker-compose downFirstly we need mysql to run the tests
docker-compose up mysqlRun all tests
go test ./...