This backend API server is responsible for managing the wallets of the players of an online casino. It provides an API for getting and updating their account balances.
To correctly run this server, ensure the following dependencies are satisfied:
-
Clone the repository
serious@dev:~$ git clone git@github.com:ageeknamedslickback/wallet-API.git
-
Set up your MySQL user, password and database using your own preferred method
-
Create an Auth0 account, add a
Backend API
app and take note of it's credentials -domain
,audience
,client ID
andclient secret
-
Create
env.sh
and add the following environment variablesexport DB_USER="" export DB_PASS="" export DB_HOST="" export DB_PORT="" export DB_NAME="" export PORT="" export GIN_MODE="" export AUTH0_DOMAIN="" export AUTH0_AUDIENCE="" export AUTH0_CLIENT_ID="" export AUTH0_CLIENT_SECRET="" export AUTH0_GRANT_TYPE="" export REDIS_ADDR="" export REDIS_PASSWORD="" export REDIS_DB=""
-
Install Go dependencies
serious@dev:~$ go mod tidy
-
Ensure your Redis service is properly configured and running
-
Run the server (performs the migrations to your database)
serious@dev:~$ source env.sh serious@dev:~$ go run server.go
-
Pre-populate your database with a few dummy wallets
serious@dev:~$ mysql -u <user> -p <password> mysql> INSERT INTO wallets(id,balance) VALUES(1,100); mysql> INSERT INTO wallets(id,balance) VALUES(2,10); mysql> INSERT INTO wallets(id,balance) VALUES(3,0);
-
Call the APIs on any client of your choice
-
To run any API you have to first get an access token for authorization
Post:
/access_token
Response
{ "response": { "access_token": "", "token_type": "Bearer", "expires_in": 86400 } }
-
For every request, pass the
access token
in theAuthorization Header
{ "Authorization": "Bearer <access token>" }
The server is covered by unit, integration and acceptance tests
serious@dev:~$ go test -v ./...
Export this collection to postman (if you are using it) to run the APIs: