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

@ -15,7 +15,7 @@ import (
func init() {
router.GET("/api/teams/:tid/issue.json", apiHandler(teamHandler(
func(team fic.Team, _ []byte) (interface{}, error) {
func(team *fic.Team, _ []byte) (interface{}, error) {
return team.MyIssueFile()
})))
@ -48,35 +48,35 @@ func getClaims(_ httprouter.Params, _ []byte) (interface{}, error) {
return fic.GetClaims()
}
func getTeamClaims(team fic.Team, _ []byte) (interface{}, error) {
func getTeamClaims(team *fic.Team, _ []byte) (interface{}, error) {
return team.GetClaims()
}
func getExerciceClaims(exercice fic.Exercice, _ []byte) (interface{}, error) {
func getExerciceClaims(exercice *fic.Exercice, _ []byte) (interface{}, error) {
return exercice.GetClaims()
}
func getClaimLastUpdate(claim fic.Claim, _ []byte) (interface{}, error) {
func getClaimLastUpdate(claim *fic.Claim, _ []byte) (interface{}, error) {
return claim.GetLastUpdate()
}
type ClaimExported struct {
Id int64 `json:"id"`
Subject string `json:"subject"`
IdTeam *int64 `json:"id_team"`
Team *fic.Team `json:"team"`
IdExercice *int64 `json:"id_exercice"`
Exercice *fic.Exercice `json:"exercice"`
IdAssignee *int64 `json:"id_assignee"`
Assignee *fic.ClaimAssignee `json:"assignee"`
Creation time.Time `json:"creation"`
LastUpdate time.Time `json:"last_update"`
State string `json:"state"`
Priority string `json:"priority"`
Descriptions []fic.ClaimDescription `json:"descriptions"`
Id int64 `json:"id"`
Subject string `json:"subject"`
IdTeam *int64 `json:"id_team"`
Team *fic.Team `json:"team"`
IdExercice *int64 `json:"id_exercice"`
Exercice *fic.Exercice `json:"exercice"`
IdAssignee *int64 `json:"id_assignee"`
Assignee *fic.ClaimAssignee `json:"assignee"`
Creation time.Time `json:"creation"`
LastUpdate time.Time `json:"last_update"`
State string `json:"state"`
Priority string `json:"priority"`
Descriptions []*fic.ClaimDescription `json:"descriptions"`
}
func showClaim(claim fic.Claim, _ []byte) (interface{}, error) {
func showClaim(claim *fic.Claim, _ []byte) (interface{}, error) {
var e ClaimExported
var err error
if e.Team, err = claim.GetTeam(); err != nil {
@ -130,7 +130,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
if team, err := fic.GetTeam(*uc.IdTeam); err != nil {
return nil, fmt.Errorf("Unable to get associated team: %w", err)
} else {
t = &team
t = team
}
} else {
t = nil
@ -141,7 +141,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
if exercice, err := fic.GetExercice(*uc.IdExercice); err != nil {
return nil, fmt.Errorf("Unable to get associated exercice: %w", err)
} else {
e = &exercice
e = exercice
}
} else {
e = nil
@ -152,7 +152,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
if assignee, err := fic.GetAssignee(*uc.IdAssignee); err != nil {
return nil, fmt.Errorf("Unable to get associated assignee: %w", err)
} else {
a = &assignee
a = assignee
}
} else {
a = nil
@ -180,7 +180,7 @@ func generateTeamIssuesFile(team fic.Team) error {
return nil
}
func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
func addClaimDescription(claim *fic.Claim, body []byte) (interface{}, error) {
var ud fic.ClaimDescription
if err := json.Unmarshal(body, &ud); err != nil {
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
@ -199,7 +199,7 @@ func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
}
}
func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
func updateClaimDescription(claim *fic.Claim, body []byte) (interface{}, error) {
var ud fic.ClaimDescription
if err := json.Unmarshal(body, &ud); err != nil {
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
@ -216,7 +216,7 @@ func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
}
}
func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
func updateClaim(claim *fic.Claim, body []byte) (interface{}, error) {
var uc ClaimUploaded
if err := json.Unmarshal(body, &uc); err != nil {
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
@ -261,7 +261,7 @@ func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
}
}
func deleteClaim(claim fic.Claim, _ []byte) (interface{}, error) {
func deleteClaim(claim *fic.Claim, _ []byte) (interface{}, error) {
return claim.Delete()
}
@ -269,7 +269,7 @@ func getAssignees(_ httprouter.Params, _ []byte) (interface{}, error) {
return fic.GetAssignees()
}
func showClaimAssignee(assignee fic.ClaimAssignee, _ []byte) (interface{}, error) {
func showClaimAssignee(assignee *fic.ClaimAssignee, _ []byte) (interface{}, error) {
return assignee, nil
}
func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) {
@ -281,7 +281,7 @@ func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) {
return fic.NewClaimAssignee(ua.Name)
}
func updateClaimAssignee(assignee fic.ClaimAssignee, body []byte) (interface{}, error) {
func updateClaimAssignee(assignee *fic.ClaimAssignee, body []byte) (interface{}, error) {
var ua fic.ClaimAssignee
if err := json.Unmarshal(body, &ua); err != nil {
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
@ -296,6 +296,6 @@ func updateClaimAssignee(assignee fic.ClaimAssignee, body []byte) (interface{},
}
}
func deleteClaimAssignee(assignee fic.ClaimAssignee, _ []byte) (interface{}, error) {
func deleteClaimAssignee(assignee *fic.ClaimAssignee, _ []byte) (interface{}, error) {
return assignee.Delete()
}