Avoid Atoi to avoid int convertion
This commit is contained in:
parent
8702db568c
commit
0f48b27a04
|
@ -112,7 +112,7 @@ func teamHandler(f func(fic.Team, []byte) (interface{}, error)) func(httprouter.
|
|||
|
||||
func themeHandler(f func(fic.Theme, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if thid, err := strconv.Atoi(string(ps.ByName("thid"))); err != nil {
|
||||
if thid, err := strconv.ParseInt(string(ps.ByName("thid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if theme, err := fic.GetTheme(thid); err != nil {
|
||||
return nil, err
|
||||
|
@ -124,9 +124,9 @@ func themeHandler(f func(fic.Theme, []byte) (interface{}, error)) func(httproute
|
|||
|
||||
func exerciceHandler(f func(fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if eid, err := strconv.Atoi(string(ps.ByName("eid"))); err != nil {
|
||||
if eid, err := strconv.ParseInt(string(ps.ByName("eid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if exercice, err := fic.GetExercice(int64(eid)); err != nil {
|
||||
} else if exercice, err := fic.GetExercice(eid); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return f(exercice, body)
|
||||
|
@ -155,9 +155,9 @@ func themedExerciceHandler(f func(fic.Theme, fic.Exercice, []byte) (interface{},
|
|||
|
||||
func hintHandler(f func(fic.EHint, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if hid, err := strconv.Atoi(string(ps.ByName("hid"))); err != nil {
|
||||
if hid, err := strconv.ParseInt(string(ps.ByName("hid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if hint, err := fic.GetHint(int64(hid)); err != nil {
|
||||
} else if hint, err := fic.GetHint(hid); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return f(hint, body)
|
||||
|
@ -173,13 +173,13 @@ func flagHandler(f func(fic.Flag, fic.Exercice, []byte) (interface{}, error)) fu
|
|||
return nil, nil
|
||||
})(ps, body)
|
||||
|
||||
if kid, err := strconv.Atoi(string(ps.ByName("kid"))); err != nil {
|
||||
if kid, err := strconv.ParseInt(string(ps.ByName("kid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if flags, err := exercice.GetFlags(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, flag := range flags {
|
||||
if flag.Id == int64(kid) {
|
||||
if flag.Id == kid {
|
||||
return f(flag, exercice, body)
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func choiceHandler(f func(fic.FlagChoice, fic.Exercice, []byte) (interface{}, er
|
|||
return nil, nil
|
||||
})(ps, body)
|
||||
|
||||
if cid, err := strconv.Atoi(string(ps.ByName("cid"))); err != nil {
|
||||
if cid, err := strconv.ParseInt(string(ps.ByName("cid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if choice, err := flag.GetChoice(cid); err != nil {
|
||||
return nil, err
|
||||
|
@ -216,7 +216,7 @@ func quizHandler(f func(fic.MCQ, fic.Exercice, []byte) (interface{}, error)) fun
|
|||
return nil, nil
|
||||
})(ps, body)
|
||||
|
||||
if qid, err := strconv.Atoi(string(ps.ByName("qid"))); err != nil {
|
||||
if qid, err := strconv.ParseInt(string(ps.ByName("qid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if mcqs, err := exercice.GetMCQ(); err != nil {
|
||||
return nil, err
|
||||
|
@ -239,13 +239,13 @@ func exerciceFileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(ht
|
|||
return nil, nil
|
||||
})(ps, body)
|
||||
|
||||
if fid, err := strconv.Atoi(string(ps.ByName("fid"))); err != nil {
|
||||
if fid, err := strconv.ParseInt(string(ps.ByName("fid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if files, err := exercice.GetFiles(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, file := range files {
|
||||
if file.Id == int64(fid) {
|
||||
if file.Id == fid {
|
||||
return f(file, body)
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ func exerciceFileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(ht
|
|||
|
||||
func eventHandler(f func(fic.Event, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if evid, err := strconv.Atoi(string(ps.ByName("evid"))); err != nil {
|
||||
if evid, err := strconv.ParseInt(string(ps.ByName("evid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if event, err := fic.GetEvent(evid); err != nil {
|
||||
return nil, err
|
||||
|
@ -268,7 +268,7 @@ func eventHandler(f func(fic.Event, []byte) (interface{}, error)) func(httproute
|
|||
|
||||
func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if cid, err := strconv.Atoi(string(ps.ByName("cid"))); err != nil {
|
||||
if cid, err := strconv.ParseInt(string(ps.ByName("cid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if claim, err := fic.GetClaim(cid); err != nil {
|
||||
return nil, err
|
||||
|
@ -280,9 +280,9 @@ func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httproute
|
|||
|
||||
func claimAssigneeHandler(f func(fic.ClaimAssignee, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if aid, err := strconv.Atoi(string(ps.ByName("aid"))); err != nil {
|
||||
if aid, err := strconv.ParseInt(string(ps.ByName("aid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if assignee, err := fic.GetAssignee(int64(aid)); err != nil {
|
||||
} else if assignee, err := fic.GetAssignee(aid); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return f(assignee, body)
|
||||
|
@ -292,7 +292,7 @@ func claimAssigneeHandler(f func(fic.ClaimAssignee, []byte) (interface{}, error)
|
|||
|
||||
func fileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if fileid, err := strconv.Atoi(string(ps.ByName("fileid"))); err != nil {
|
||||
if fileid, err := strconv.ParseInt(string(ps.ByName("fileid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else if file, err := fic.GetFile(fileid); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -115,7 +115,7 @@ func bindingFiles(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
}
|
||||
|
||||
func getExercice(args []string) (fic.Exercice, error) {
|
||||
if tid, err := strconv.Atoi(string(args[0])); err != nil {
|
||||
if tid, err := strconv.ParseInt(string(args[0]), 10, 64); err != nil {
|
||||
return fic.Exercice{}, err
|
||||
} else if theme, err := fic.GetTheme(tid); err != nil {
|
||||
return fic.Exercice{}, err
|
||||
|
|
|
@ -30,14 +30,14 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
|
|||
log.Println(id, "New submission receive", pathname)
|
||||
|
||||
// Parse exercice_id argument
|
||||
eid, err := strconv.Atoi(exercice_id)
|
||||
eid, err := strconv.ParseInt(exercice_id, 10, 64)
|
||||
if err != nil {
|
||||
log.Printf("%s [ERR] %s is not a valid number: %s\n", id, exercice_id, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Find the given exercice
|
||||
exercice, err := fic.GetExercice(int64(eid))
|
||||
exercice, err := fic.GetExercice(eid)
|
||||
if err != nil {
|
||||
log.Printf("%s [ERR] Unable to find exercice %d: %s\n", id, eid, err)
|
||||
return
|
||||
|
|
|
@ -20,7 +20,7 @@ func SubmissionHandler(w http.ResponseWriter, r *http.Request, team string, sURL
|
|||
}
|
||||
|
||||
// Check exercice validity then save the submission
|
||||
if pex, err := strconv.Atoi(sURL[0]); err != nil {
|
||||
if pex, err := strconv.ParseInt(sURL[0], 10, 64); err != nil {
|
||||
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
||||
return
|
||||
} else if exercice := fmt.Sprintf("%d", pex); len(exercice) < 1 {
|
||||
|
|
|
@ -59,13 +59,9 @@ func GetEvents() ([]Event, error) {
|
|||
}
|
||||
|
||||
// GetEvent retrieves the event with the given id
|
||||
func GetEvent(id int) (Event, error) {
|
||||
var e Event
|
||||
if err := DBQueryRow("SELECT id_event, txt, kind, time FROM events WHERE id_event=?", id).Scan(&e.Id, &e.Text, &e.Kind, &e.Time); err != nil {
|
||||
return e, err
|
||||
}
|
||||
|
||||
return e, nil
|
||||
func GetEvent(id int64) (e Event, err error) {
|
||||
err = DBQueryRow("SELECT id_event, txt, kind, time FROM events WHERE id_event=?", id).Scan(&e.Id, &e.Text, &e.Kind, &e.Time)
|
||||
return
|
||||
}
|
||||
|
||||
// NewEvent creates a new event in the database and returns the corresponding structure
|
||||
|
|
|
@ -161,12 +161,9 @@ func (e *Exercice) FixURLId() bool {
|
|||
}
|
||||
|
||||
// GetThemeId returns the theme's id for the Exercice.
|
||||
func (e Exercice) GetThemeId() (int, error) {
|
||||
var tid int
|
||||
if err := DBQueryRow("SELECT id_theme FROM exercices WHERE id_exercice=?", e.Id).Scan(&tid); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return tid, nil
|
||||
func (e Exercice) GetThemeId() (tid int64, err error) {
|
||||
err = DBQueryRow("SELECT id_theme FROM exercices WHERE id_exercice=?", e.Id).Scan(&tid)
|
||||
return
|
||||
}
|
||||
|
||||
// GetTheme returns the parent Theme where the Exercice lives.
|
||||
|
|
|
@ -67,9 +67,9 @@ func GetFiles() ([]EFile, error) {
|
|||
}
|
||||
|
||||
// GetFile retrieves the file with the given id.
|
||||
func GetFile(id int) (f EFile, err error) {
|
||||
func GetFile(id int64) (f EFile, err error) {
|
||||
err = DBQueryRow("SELECT id_file, origin, path, name, cksum, size FROM exercice_files WHERE id_file = ?", id).Scan(&f.Id, &f.origin, &f.Path, &f.Name, &f.Checksum, &f.Size)
|
||||
return f, err
|
||||
return
|
||||
}
|
||||
|
||||
// GetFileByPath retrieves the file that should be found at the given location.
|
||||
|
|
|
@ -40,7 +40,7 @@ func (f Flag) GetChoices() ([]FlagChoice, error) {
|
|||
}
|
||||
|
||||
// GetChoice returns a choice for the given Flag.
|
||||
func (f Flag) GetChoice(id int) (c FlagChoice, err error) {
|
||||
func (f Flag) GetChoice(id int64) (c FlagChoice, err error) {
|
||||
if errr := DBQueryRow("SELECT id_choice, id_flag, label, response FROM flag_choices WHERE id_choice = ?", id).Scan(&c.Id, &c.IdFlag, &c.Label, &c.Value); errr != nil {
|
||||
return c, errr
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ type myTeamFlag struct {
|
|||
Choices map[string]string `json:"choices,omitempty"`
|
||||
}
|
||||
type myTeamExercice struct {
|
||||
ThemeId int `json:"theme_id"`
|
||||
ThemeId int64 `json:"theme_id"`
|
||||
Statement string `json:"statement"`
|
||||
Overview string `json:"overview,omitempty"`
|
||||
Hints []myTeamHint `json:"hints,omitempty"`
|
||||
|
|
|
@ -37,7 +37,7 @@ func GetThemes() ([]Theme, error) {
|
|||
}
|
||||
|
||||
// GetTheme retrieves a Theme from its identifier.
|
||||
func GetTheme(id int) (Theme, error) {
|
||||
func GetTheme(id int64) (Theme, error) {
|
||||
var t Theme
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro, image FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Image); err != nil {
|
||||
return t, err
|
||||
|
|
|
@ -17,7 +17,7 @@ type Claim struct {
|
|||
}
|
||||
|
||||
// GetClaim retrieves the claim with the given identifier.
|
||||
func GetClaim(id int) (c Claim, err error) {
|
||||
func GetClaim(id int64) (c Claim, err error) {
|
||||
err = DBQueryRow("SELECT id_claim, subject, id_team, id_assignee, creation, state, priority FROM claims WHERE id_claim = ?", id).Scan(&c.Id, &c.Subject, &c.IdTeam, &c.IdAssignee, &c.Creation, &c.State, &c.Priority)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user