This is a semple leaderboard project.
- The leaderboard has 2 feature
- One feature is the receive gaming score from a client (with its client ID).
- Second to show latest top 10 highest score clients.
- The leaderboard should reset every 10 minutes.
- Using Golang Iris framework to build api
- Using redis for database
- Use the
zset
method to record customer scores to get a sorted data structure. - If the requirement is to start timing after the leaderboard has data. the TTL mechanism can be used to complete the reset leaderboard.
- If the requirement is is global ticker. there is a cronjob designed to complete the reset leaderboard.
- Use the
- Layered Architecture Design
- Github Actions for CI
- redismock
- tests use
- mock
- tests use
- json-iterator
- decode encode
- cron
- time tasks
- cobra
- for CLI interactions
- testify
- tests use
- fx
- dependency injection
- zap
- logger
💡 Please check that the computer environment has docker service! Run the following command.
git clone https://github.com/adam6313/leaderboard
docker network create leaderboard
docker network create leaderboard
After the above steps are completed, you can use the following command to check whether the service starts successfully
curl --location --request GET '127.0.0.1:8080'
URI | Method | Desc |
---|---|---|
/ | GET | get service version |
/api/v1/score | POST | record client score |
/api/v1/dup/score | POST | Allow duplicate clientID to appear in leaderboard |
/api/v1/leaderboard | GET | get latest top 10 highest score clients |