Ejemplo n.º 1
0
// LeaderboardHandler displays information for a given leaderboard
func LeaderboardHandler(w http.ResponseWriter, r *http.Request) {

	// Get leaderboard object
	vars := mux.Vars(r)
	ldbID, _ := strconv.Atoi(vars["id"])

	l, err := steam.GetLeaderboard(ldbID)

	if err != nil {
		http.Redirect(w, r, "/", http.StatusNotFound)
		return
	}

	// Pagination
	page := getPage(r)
	u, d, pagination := paginate.Paginate(len(l.Entries), page, 100)

	data := LeaderboardData{
		Entries: l.Entries[u:d],
		Page:    pagination,
		Name:    l.Name,
		Count:   len(l.Entries),
		ID:      l.UID,
		Daily:   l.IsDaily(),
		LastUpdateDisplayable: l.LastUpdate.Format(time.Stamp),
	}

	// HTML rendering
	t, err := template.ParseFiles(layoutPath("default"), templatePath("leaderboard"))
	if err != nil {
		common.Err("SERVER", fmt.Sprintf("%v", err))
	} else {
		t.Execute(w, data)
	}
}
Ejemplo n.º 2
0
// HomeHandler is the home of our website
func HomeHandler(w http.ResponseWriter, r *http.Request) {

	// Try to refresh player count
	refreshPlayerCount()

	// Get leaderboards
	leaderboards, err := steam.GetLeaderboards()
	if err != nil {
		common.Err("SERVER", fmt.Sprintf("%v", err))
	}

	// Prepare view
	var data IndexData

	// -- Paginate
	page := getPage(r)

	u, d, pagination := paginate.Paginate(len(leaderboards.List), page, LEADERBOARDSHOMECOUNT)

	data.Leaderboards = leaderboards.List[u:d]
	data.Page = pagination
	data.PlayerCount = playerCount

	// -- HTML rendering
	t, err := template.ParseFiles(layoutPath("default"), templatePath("index"))
	if err != nil {
		common.Err("SERVER", fmt.Sprintf("%v", err))
	} else {
		t.Execute(w, data)
	}
}