This is a Go backend for an external game.
In order for this backend to easily interface with any external game developped in any language (in a microservice spirit), this backend is built as a RESTful API. The following elements can be managed through the API: players, teams, games, achievements, and stats.
Achievements and statistics are admin operations so they cannot be extended through the API but they can be easily extended in data.go
. See below for more details.
In order to automatically populate the backend and easily test it, the tests are pretty comprehensive. See below.
Stats can be modified (more can be added, or some can be removed) by doing the following:
- modify the
Stats
struct indata.go
- modify the
IncrementStats
method accordingly indata.go
- (optional) modify the
CalculateGlobalStats
method indata.go
if needed
Alternatively a new type of stats can also be created and this type should implement the StatsIncrementer
interface (found in data.go
) in order for statistics to be properly incremented.
Achievements can be modified (more can be added, or some can be removed) by doing the following:
- modify the
Achievements
struct indata.go
- modify the
CalculateAchievements
method accordingly indata.go
For convenience and documentation, an AchievementsCalculator
interface also exists in data.go
but is not used yet. Every new achievements types should implement this interface.
POST /teams
withname
parameter: create a team by providing a team name, and return the team createdDELETE /teams/{id}
: delete a team by providing its team idGET /teams
: list all teams
POST /teams/{id}/players
withpseudo
parameter: create a player and affect him to a team by providing a pseudo and a team id, and return the player createdDELETE /teams/{teamId}/players/{playerId}
: remove a player by providing his id and its team id
POST /games
withname
,team1Id
andteam2Id
parameters: create a new game by giving a name and affect 2 teams to this game by providing their team ids, and return the game createdPUT /games/{id}
withteamId
parameter: stop a game by providing the game id and the team id of the winning teamGET /games
: list all games
GET /games/{gameId}/players/{playerId}/achievements
: list all achievements from a player by providing the player id
GET /games/{gameId}/players/{playerId}/stats
: list all stats from a player in a game by providing the game id and player idPUT /games/{gameId}/players/{playerId}/stats
withname
parameter: increment by 1 the stat of a player in a game by providing the stat name (choices are:nbAttemptedAttacks
,nbHits
,damageDone
,nbKills
,nbFirstHitKills
,nbAssists
,nbSpellCasts
,spellDamageDone
)
- get the
osmo_test
binary file sent by email - launch it. For example on Linux open the terminal and launch
./osmo_test
in console. - the backend is now running at the following address
http://127.0.0.1:8000
, and can be consumed through curl, Postman, an internet browser...
Tests are in the endpoints_test.go
file. Run the whole test file with go test -v
.
Running the whole test file can be considered as an end to end test. It will create 4 teams and 11 players, and then create a game of 2 teams (made up of 3 players each), increment the player 1 stats, stop the game, and retrieve the player 1's "Bruiser" achievements. The most crucial is the TestAchievementsListingHandler
test which actually checks that the "Bruiser" achievement was actually granted to player 1.
- Implement the possibility for a player to move to another team or play another game (which would reinitialize his personal stats except the total time played, but the player stats inside a game would be kept).
- Check that the same user is not in the 2 teams at the same time during a game.
- Check that the same user is not playing 2 games at the same time.