This is a simple golang application that exposes deck APIs useful for playing card games.
- Install go version
1.18.1or above - Clone this repository
- Prepare config file
The application reads the configurations from .app.yaml file or the environment variables. The app.yaml is a sample config that can be used to create the actual config file. Execute the following command to create a app config file.
cp app.yaml .app.yamlYou can edit the config values inside .app.yaml file.
- Start the server directly using below command
go run main.goOr, If you want to build & run executable then below run commands.
go build
./deck-apiThis will start the http server on the host on port mentioned in the .app.yaml config file.
- Run the following command from the root directory
go test -v -cover ./...This will execute all the tests and also prints the code coverage percentage.
Create a new deck.
| Name | Type | Optional | Description |
|---|---|---|---|
| shuffled | boolean | yes | Can be set as true/false. If true, the cards from the deck will be shuffled. |
| cards | csv | yes | CSV of card codes (e.g. AS,KD,AC,2C,KH). If provided, deck will be created with only specified cards otherwise deck will be created with all cards. |
Open a deck using deck uuid.
| Param Name | Type | Optional | Description |
|---|---|---|---|
| id | uuid (string) | no | The uuid of deck to be opened. |
Draw card(s) from a specific deck.
| Name | Type | Optional | Description |
|---|---|---|---|
| id | uuid (string) | no | The uuid of deck. |
| count | int | no | Number of cards to draw from the deck. |