leaderboard

package module
v0.0.0-...-a5e06f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2016 License: MIT Imports: 4 Imported by: 2

README

Leaderboard

A leaderboard written in Go using Redis database.

Features

  • Create multiple Leaderboards by name
  • You can rank a member with and the leaderboard will be updated automatically
  • Remove a member from a specific Leaderboard
  • Get total of users in a specific Leaderboard and also how many pages it has.
  • Get leaders on any page
  • Get an "Around Me" leaderboard for a member
  • Get rank and score for an arbitrary list of members (e.g. friends)

How to use

Create a new leaderboard or attach to an existing leaderboard named 'highscores':

    highScore := NewLeaderboard(RedisSettings{
    	Host: "localhost:6379", 
    	Password: "mypassword",
    }, "highscores", 10)
    //return a Leaderboard: Leaderboard{name:"highscores", pageSize:10}

Adding members to highscores using RankMember(username, score):

    highScore.RankMember("dayvson", 9876)
    highScore.RankMember("arthur", 2000123)
    highScore.RankMember("felipe", 100000)

You can call RankMember with the same member and the leaderboard will be updated automatically:

	highScore.RankMember("dayvson", 7481523)
	//return an user: User{name:"dayvson", score:7481523, rank:1}

Getting a total members on highscores:

	highScore.TotalMembers()
	//return an int: 3

Getting the rank from a member:

	highScore.GetRank("dayvson")
	//return an int: 1

Getting a member from a rank position:

	highScore.GetMemberByRank(2)
	//return an user: User{name:"felipe", score:100000, rank:2}

Getting members around you:

	highScore.GetAroundMe("felipe")
	//return an array of users around you [pageSize]User:

Getting Leaders by page:

	highScore.GetLeaders(1)
	//return an array of users with highest score in a first page (you can specify any page): [pageSize]User

Installation

Install Leaderboard using the "go get" command:

go get github.com/dayvson/go-leaderboard

Testing

make test

Dependencies

  • Go language distribution
  • redigo (github.com/garyburd/redigo/redis)

Contributing

  • Contributions are welcome.
  • Take care to maintain the existing coding style.
  • Add unit tests for any new or changed functionality.
  • Open a pull request :)

License

© 2013, Maxwell Dayvson da Silva. Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Leaderboard

type Leaderboard struct {
	Settings RedisSettings
	Name     string
	PageSize int
}

func NewLeaderboard

func NewLeaderboard(settings RedisSettings, name string, pageSize int) Leaderboard

func (*Leaderboard) GetAroundMe

func (l *Leaderboard) GetAroundMe(username string) []User

func (*Leaderboard) GetLeaders

func (l *Leaderboard) GetLeaders(page int) []User

func (*Leaderboard) GetMember

func (l *Leaderboard) GetMember(username string) (User, error)

func (*Leaderboard) GetMemberByRank

func (l *Leaderboard) GetMemberByRank(position int) User

func (*Leaderboard) GetRank

func (l *Leaderboard) GetRank(username string) int

func (*Leaderboard) RankMember

func (l *Leaderboard) RankMember(username string, score int) (User, error)

func (*Leaderboard) RemoveMember

func (l *Leaderboard) RemoveMember(username string) (User, error)

func (*Leaderboard) TotalMembers

func (l *Leaderboard) TotalMembers() int

func (*Leaderboard) TotalPages

func (l *Leaderboard) TotalPages() int

type RedisSettings

type RedisSettings struct {
	Host     string
	Password string
}

type Team

type Team struct {
	Name    string
	Members map[string]User
	Rank    int
}

type User

type User struct {
	Name  string
	Score int
	Rank  int
}

Structs model

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL