A little REST blackjack game
This code was tested with the configuration:
- Ubuntu 22.04
- Go 1.17
- PostgreSQL 14
Set your PostgreSQL DSN in .env file
$ make -f Makefile build install-migrate apply-migrations
$ ./cmd/backend
$ docker compose up
$ docker exec BACKEND_CONTAINER_NAME make -f Makefile apply-migrations
You can access the game backend using Postman or using the provided command-line client:
$ ./cmd/client
If you access it using Postman than use the provided OpenAPI file:
/api/openapi/http_api.yml
Name | Description |
---|---|
/api/player | Gets the player data |
/player/create | Creates a player with the given credentials |
/player/stats | Displayes the player's gaming history |
/game/state | Describes the current state of the game and next possible actions |
/game/action | Perform the next action |
Basically the game works in an endless cycle in which a player performs an action and then requests description of the new game state.
- Requests are received by the autogenerated HTTP server layer: internal/ports/http_api/
- The extracted data is sent to the application layer: internal/app/
- In the application layer domain objects (internal/domain/) are created from database repositories (internal/adapters/gorm/)
- All the game logic is managed by domain objects:
- internal/domain/entry - performs authentication
- internal/domain/player - stores player's balance and stats
- internal/domain/game/session - stores all the game data
- internal/domain/game/actions - is the state machine that describes the Blackjack gameplay
- internal/domain/game/deck - describes the card deck