Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Leaderboard ¶
type Leaderboard struct {
// contains filtered or unexported fields
}
Leaderboard knows how to interact with top users
func New ¶
func New(topUserGetter TopUserGetter, topScoreNotifier TopScoreNotifier) *Leaderboard
New creates a new Leaderboard ready to do leaderboard things
Accept interfaces, return implementations!
func (*Leaderboard) NotifyTopPlayers ¶
func (l *Leaderboard) NotifyTopPlayers(ctx context.Context, top int) error
NotifyTopPlayers will send a notification to the top X players
type TopScoreNotifier ¶
TopScoreNotifier notifies users they have a high score
As above, focus on how this feels to read in terms of understanding the code in this package.
type TopUserGetter ¶
TopUserGetter gets top users from somewhere
Notice that we're tying ourselves to the database package here, but we'll live with it. The important part here is that this is just a tiny subsection of the full database functionality, because this is all a leaderboard needs to care about.
Think about how it feels to read this and what it tells you about what the code in this package does compared to what it would be like seeing the full Database functionality at Leaderboard's disposal. When we declare our interface locally like this, it makes the intent MUCH clearer to the reader/maintainer!