Follow the leader with help from a server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

json_structs.go 938B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // NGnius 2020-01-30
  2. package main
  3. import (
  4. "strconv"
  5. "time"
  6. )
  7. // Board a leaderboard
  8. type Board struct {
  9. ID int64
  10. Entries []Entry
  11. Name string
  12. }
  13. // Entry an entry in a leaderboard
  14. type Entry struct {
  15. ID int64
  16. Rank int64
  17. Score int64
  18. PlayerName string
  19. PlayerURL string
  20. }
  21. // Player a player
  22. type Player struct {
  23. ID int64
  24. Name string
  25. Entries []Entry
  26. }
  27. // URL get the player's URL
  28. func (p *Player) URL() string {
  29. return "/player/" + strconv.Itoa(int(p.ID))
  30. }
  31. // Result a query result
  32. type Result struct {
  33. Items []interface{}
  34. Elapsed int64
  35. Count int
  36. Query string
  37. URL string
  38. Start time.Time
  39. }
  40. // NewResult build a query struct
  41. func NewResult(q string, url string) (r Result) {
  42. r.Start = time.Now()
  43. r.Query = q
  44. r.URL = url
  45. return
  46. }
  47. // Complete finish the result
  48. func (r *Result) Complete() {
  49. r.Count = len(r.Items)
  50. r.Elapsed = time.Since(r.Start).Milliseconds()
  51. }