server/libfic/team_export.go

39 lines
833 B
Go

package fic
import (
"fmt"
)
// exportedTeam is a structure representing a Team, as exposed to players.
type exportedTeam struct {
Name string `json:"name"`
Color string `json:"color"`
Rank int `json:"rank"`
Points float64 `json:"score"`
}
// Exportedteam creates the structure to respond as teams.json.
func ExportTeams() (ret map[string]exportedTeam, err error) {
var teams []Team
var rank map[int64]int
if teams, err = GetTeams(); err != nil {
return
} else if rank, err = GetRank(); err != nil {
return nil, err
} else {
ret = map[string]exportedTeam{}
for _, team := range teams {
points, _ := team.GetPoints()
ret[fmt.Sprintf("%d", team.Id)] = exportedTeam{
team.Name,
fmt.Sprintf("#%x", team.Color),
rank[team.Id],
points,
}
}
return
}
}