package api import ( "strconv" "srs.epita.fr/fic-server/libfic" "github.com/julienschmidt/httprouter" ) func init() { router.GET("/api/exercices/", apiHandler(listExercices)) router.GET("/api/exercices/:eid", apiHandler(exerciceHandler(showExercice))) } func exerciceHandler(f func(QAUser, fic.Exercice, []byte) (interface{}, error)) func(QAUser, httprouter.Params, []byte) (interface{}, error) { return func(u QAUser, ps httprouter.Params, body []byte) (interface{}, error) { if eid, err := strconv.ParseInt(string(ps.ByName("eid")), 10, 64); err != nil { return nil, err } else if exercice, err := fic.GetExercice(eid); err != nil { return nil, err } else { return f(u, exercice, body) } } } func listExercices(_ QAUser, _ httprouter.Params, body []byte) (interface{}, error) { // List all exercices return fic.GetExercices() } func showExercice(_ QAUser, exercice fic.Exercice, body []byte) (interface{}, error) { return exercice, nil }