This project exposes an API to simulate deck of cards which can be used for card games.
Written in Go (Golang 1.18) using gin as web framework, Postgres as database, zap for logging, prometheus and grafana for monitoring.
- Use
make build
to build the web server andmake start
to start the server. Server runs onlocalhost:8080
. - Use
make test
runs the tests in a seperate docker container for isolation. - Air and docker-sync are used for live reloading during development.
- Grafana dashboard is avaialble on
localhost:3004
- Prometheus UI is accessible on
localhost:9090
git
docker
docker-compose
docker-sync (0.5.14) [Use `gem install docker-sync -v 0.5.14` for mac]
- Clone repository
git clone https://github.com/nvzard/Casino-Royale.git
- Change directory to the cloned repository
cd Casino-Royale
- Build image
make build
- Run start command
make start
make test
make clean
GET /healthcheck # ok
POST /deck # create new deck (query parameters: shuffle, cards)
GET /deck/:deck_id # open deck by id
POST /deck/:deck_id/draw # draw cards from the deck (query parameters: count)
POST /deck
Parameter | Type | Description |
---|---|---|
shuffle |
bool |
Optional. true or false |
cards |
string |
Optional. Custom Cards Code: AS,1S,2S, etc |
POST /deck
{
"deck_id": "a251071b-662f-44b6-ba11-e24863039c59",
"shuffled": false,
"remaining": 52
}
POST /deck?shuffle=true&cards=AS,2S
{
"deck_id": "9bc9d90e-3056-40c7-94bc-241915cbee4d",
"shuffled": true,
"remaining": 2
}
GET /deck/:deck_id
GET /deck/a251071b-662f-44b6-ba11-e24863039c59
{
"deck_id": "a251071b-662f-44b6-ba11-e24863039c59",
"shuffled": false,
"remaining": 3,
"cards": [
{
"value": "ACE",
"suit": "SPADES",
"code": "AS"
},
{
"value": "KING",
"suit": "HEARTS",
"code": "KH"
},
{
"value": "8",
"suit": "CLUBS",
"code": "8C"
}
]
}
POST /deck/:deck_id/draw
Parameter | Type | Description |
---|---|---|
count |
string |
Optional. Number of cards to draw [default=1] |
POST /deck/a251071b-662f-44b6-ba11-e24863039c59/draw
{
"cards": [
{
"value": "QUEEN",
"suit": "HEARTS",
"code": "QH"
}
]
}
POST /deck/:deck_id/draw?count=2
{
"cards": [
{
"value": "KING",
"suit": "HEARTS",
"code": "KH"
},
{
"value": "8",
"suit": "CLUBS",
"code": "8C"
}
]
}
Some of the improvements that can be made but were skipped due to time constraints.
- Refactor project structure to follow go guidelines. Currently it is similar to Rails/JS ecosystem.
- Write more tests and improve code coverage.
- Add error handling mechanism and single store for all strings.
- Setup CI/CD pipeline for testing and deployment.
- Add some kind of authentication mechanism. Basic Auth or JWT.
Please open an issue and let me know incase I messed something up. Some feedback would really help me up my go game.