Use pointer receiver more offen

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

View file

@ -16,7 +16,7 @@ type wantChoices struct {
FlagId int `json:"id"`
}
func treatWantChoices(pathname string, team fic.Team) {
func treatWantChoices(pathname string, team *fic.Team) {
// Generate a unique identifier to follow the request in logs
bid := make([]byte, 5)
binary.LittleEndian.PutUint32(bid, rand.Uint32())
@ -43,7 +43,7 @@ func treatWantChoices(pathname string, team fic.Team) {
} else if err = team.DisplayChoices(flag); err != nil {
log.Printf("%s [ERR] %s\n", id, err)
} else {
genTeamQueue <- &team
genTeamQueue <- team
if err = os.Remove(pathname); err != nil {
log.Printf("%s [ERR] %s\n", id, err)
}

View file

@ -96,7 +96,7 @@ func consumer() {
}
// Generate issues.json for a given team
func genTeamIssuesFile(team fic.Team) error {
func genTeamIssuesFile(team *fic.Team) error {
dirPath := path.Join(TeamsDir, fmt.Sprintf("%d", team.Id))
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
@ -237,7 +237,7 @@ func genAll() {
} else {
for _, team := range teams {
myteam := team // team is reused, we need to create a new variable here to store the value
genTeamQueue <- &myteam
genTeamQueue <- myteam
}
}
}

View file

@ -18,7 +18,7 @@ type askOpenHint struct {
HintId int64 `json:"id"`
}
func treatOpeningHint(pathname string, team fic.Team) {
func treatOpeningHint(pathname string, team *fic.Team) {
// Generate a unique identifier to follow the request in logs
bid := make([]byte, 5)
binary.LittleEndian.PutUint32(bid, rand.Uint32())
@ -54,7 +54,7 @@ func treatOpeningHint(pathname string, team fic.Team) {
log.Printf("%s [WRN] Unable to create event: %s\n", id, err)
}
genTeamQueue <- &team
genTeamQueue <- team
appendGenQueue(genStruct{Type: GenEvents})
if err = os.Remove(pathname); err != nil {
log.Printf("%s [ERR] %s\n", id, err)

View file

@ -19,7 +19,7 @@ type IssueUpload struct {
Description string `json:"description"`
}
func treatIssue(pathname string, team fic.Team) {
func treatIssue(pathname string, team *fic.Team) {
// Generate a unique identifier to follow the request in logs
bid := make([]byte, 5)
binary.LittleEndian.PutUint32(bid, rand.Uint32())
@ -50,7 +50,7 @@ func treatIssue(pathname string, team fic.Team) {
log.Printf("%s [ERR] %s\n", id, err)
}
log.Printf("%s Empty issue: not treated.\n", id)
} else if desc, err := claim.AddDescription(issue.Description, fic.ClaimAssignee{Id: 0}, true); err != nil {
} else if desc, err := claim.AddDescription(issue.Description, &fic.ClaimAssignee{Id: 0}, true); err != nil {
log.Printf("%s [WRN] Unable to add description to issue: %s\n", id, err)
} else {
claim.State = "new"
@ -65,13 +65,13 @@ func treatIssue(pathname string, team fic.Team) {
} else {
var exercice *fic.Exercice = nil
if e, err := fic.GetExercice(issue.IdExercice); err == nil {
exercice = &e
exercice = e
}
if claim, err := fic.NewClaim(issue.Subject, &team, exercice, nil, "medium"); err != nil {
if claim, err := fic.NewClaim(issue.Subject, team, exercice, nil, "medium"); err != nil {
log.Printf("%s [ERR] Unable to create new issue: %s\n", id, err)
} else if len(issue.Description) > 0 {
if _, err := claim.AddDescription(issue.Description, fic.ClaimAssignee{Id: 0}, true); err != nil {
if _, err := claim.AddDescription(issue.Description, &fic.ClaimAssignee{Id: 0}, true); err != nil {
log.Printf("%s [WRN] Unable to add description to issue: %s\n", id, err)
} else {
log.Printf("%s [OOK] New issue created: id=%d\n", id, claim.Id)

View file

@ -220,7 +220,7 @@ func treat(raw_path string) {
}
}
var team fic.Team
var team *fic.Team
if team, err = fic.GetTeam(teamid); err != nil {
log.Printf("[ERR] Unable to retrieve team %d: %s\n", teamid, err)
return

View file

@ -27,11 +27,11 @@ type uTeamRegistration struct {
Members []fic.Member
}
func registrationProcess(id string, team fic.Team, members []fic.Member, team_id string) {
func registrationProcess(id string, team *fic.Team, members []fic.Member, team_id string) {
for _, m := range members {
// Force Id to 0, as it shouldn't have been defined yet
m.Id = 0
if err := team.GainMember(m); err != nil {
if err := team.GainMember(&m); err != nil {
log.Println("[WRN] Unable to add member (", m, ") to team (", team, "):", err)
}
}
@ -46,7 +46,7 @@ func registrationProcess(id string, team fic.Team, members []fic.Member, team_id
log.Println(id, "[ERR]", err)
}
genTeamQueue <- &team
genTeamQueue <- team
appendGenQueue(genStruct{Type: GenTeams})
}

View file

@ -20,7 +20,7 @@ func validTeamName(name string) bool {
return err == nil && match
}
func treatRename(pathname string, team fic.Team) {
func treatRename(pathname string, team *fic.Team) {
// Generate a unique identifier to follow the request in logs
bid := make([]byte, 5)
binary.LittleEndian.PutUint32(bid, rand.Uint32())
@ -38,7 +38,7 @@ func treatRename(pathname string, team fic.Team) {
if _, err := team.Update(); err != nil {
log.Printf("%s [WRN] Unable to change team name: %s\n", id, err)
}
genTeamQueue <- &team
genTeamQueue <- team
if _, err := fic.NewEvent(fmt.Sprintf("Souhaitons bonne chance à l'équipe <strong>%s</strong> qui vient de nous rejoindre&#160;!", html.EscapeString(team.Name)), "info"); err != nil {
log.Printf("%s [WRN] Unable to create event: %s\n", id, err)
}

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})