package group import ( "html/template" "io" "git.cliffbreak.de/haveachin/scoreboard/data" ) type previewGroup struct { ID string Name string PointSum int } type master struct { Template template.Template Groups []previewGroup } type detail struct { Template template.Template Group data.Group Games []data.Game } func newMasterPage(t template.Template, groups []data.Group) *master { previewGroups := []previewGroup{} for _, group := range groups { sum := 0 for _, score := range group.Scores { sum += score.Points } previewGroups = append(previewGroups, previewGroup{ ID: group.ID.Hex(), Name: group.Name, PointSum: sum, }) } return &master{ Template: *t.Lookup("groupMaster.html"), Groups: previewGroups, } } func newDetailPage(t template.Template, group data.Group, games []data.Game) *detail { return &detail{ Template: *t.Lookup("groupDetail.html"), Group: group, Games: games, } } func (page master) Send(w io.Writer) { page.Template.Execute(w, page) } func (page detail) Send(w io.Writer) { page.Template.Execute(w, page) }