Name | Description |
---|---|
Chi Router | For routing and middleware |
Zap | For logging |
sqlx | For ORM |
viper | For config management |
migrate | For Running DB scripts automatically |
testify, httpexpect, sqlmock | For Unit tests |
go test ./...
docker-compose up -d
- download golang 1.17
- checkout github.com/Aegon95/mytheresa-product-api
- run
go mod download
- install latest postgres and create new database called fashionstore
- update postgres details in config/config.yml
- go to cmd/api folder
- run
go run .
- it will start the server at port 3000
- Browse the api with the query params by going to http://localhost:3000/api/v1/products?category=boots&priceLessThan=90000
Decisions Taken
- The code is structured considering SOLID principles
- Didn't use any web frameworks like gin,echo etc because the usecase is simple
- Chose postgres DB to store data, to simulate actual production scenario
- Used Migrate library for handling sql scripts, its a flexible library can be moved into a cli as well
- Used chi router for better route handling and middleware management
- Stored discounts in a table, so that it can be easily modified at runtime without redeployment of app
- Ideally it's better to also use redis, because we have to frequently hit discounts table
- Used testify library, because it has good features and mock support
- Used sqlx ORM for Database Queries, its a lightweight ORM which compliments the database/sql package
- Added Docker support, so that its easily deployable