Use pointer receiver more offen

This commit is contained in:
nemunaire 2021-11-22 15:35:07 +01:00
parent 6999b4e728
commit c7569b5e54
59 changed files with 688 additions and 672 deletions

View file

@ -23,7 +23,7 @@ type ResponsesUpload struct {
MCQJ map[int]string `json:"justifications"`
}
func treatSubmission(pathname string, team fic.Team, exercice_id string) {
func treatSubmission(pathname string, team *fic.Team, exercice_id string) {
// Generate a unique identifier to follow the request in logs
bid := make([]byte, 5)
binary.LittleEndian.PutUint32(bid, rand.Uint32())
@ -80,8 +80,8 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
}
// Ensure the team didn't already solve this exercice
s, tm := team.HasSolved(exercice)
if s {
tm := team.HasSolved(exercice)
if tm != nil {
log.Printf("%s [WRN] Team %d ALREADY solved exercice %d (%s : %s)\n", id, team.Id, exercice.Id, theme.Name, exercice.Title)
return
}
@ -110,7 +110,7 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
solved, err := exercice.CheckResponse(cksum[:], responses.Keys, responses.MCQs, team)
if err != nil {
log.Println(id, "[ERR] Unable to CheckResponse:", err)
genTeamQueue <- &team
genTeamQueue <- team
return
}
@ -131,21 +131,21 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
} else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s a résolu le <strong>%d<sup>e</sup></strong> défi %s&#160;!", html.EscapeString(team.Name), lvl, theme.Name), "success"); err != nil {
log.Println(id, "[WRN] Unable to create event:", err)
}
genTeamQueue <- &team
genTeamQueue <- team
appendGenQueue(genStruct{id, GenThemes})
appendGenQueue(genStruct{id, GenTeams})
} else {
log.Printf("%s Team %d submit an invalid solution for exercice %d (%s : %s)\n", id, team.Id, exercice.Id, theme.Name, exercice.Title)
// Write event (only on first try)
if tm.Unix() == 0 {
if tm == nil {
if lvl, err := exercice.GetLevel(); err != nil {
log.Println(id, "[ERR] Unable to get exercice level:", err)
} else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s tente le <strong>%d<sup>e</sup></strong> défi %s&#160;!", html.EscapeString(team.Name), lvl, theme.Name), "warning"); err != nil {
log.Println(id, "[WRN] Unable to create event:", err)
}
}
genTeamQueue <- &team
genTeamQueue <- team
}
appendGenQueue(genStruct{id, GenEvents})