admin: Use gin-gonic as router

This commit is contained in:
nemunaire 2022-05-16 11:38:46 +02:00
parent 83468ad723
commit 8b3fbdb64a
32 changed files with 2785 additions and 1635 deletions

View file

@ -6,11 +6,12 @@ import (
"encoding/hex"
"fmt"
"io"
"net/http"
"os"
"path"
"strings"
"github.com/julienschmidt/httprouter"
"github.com/gin-gonic/gin"
_ "golang.org/x/crypto/blake2b"
"srs.epita.fr/fic-server/libfic"
@ -140,21 +141,24 @@ func SyncExerciceHints(i Importer, exercice *fic.Exercice, flagsBindings map[int
}
// ApiListRemoteExerciceHints is an accessor letting foreign packages to access remote exercice hints.
func ApiGetRemoteExerciceHints(ps httprouter.Params, _ []byte) (interface{}, error) {
theme, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
func ApiGetRemoteExerciceHints(c *gin.Context) {
theme, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, ps.ByName("exid")), nil)
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil)
if exercice != nil {
hints, errs := CheckExerciceHints(GlobalImporter, exercice)
if hints != nil {
return hints, nil
} else {
return hints, fmt.Errorf("%q", errs)
c.JSON(http.StatusOK, hints)
return
}
} else {
return exercice, fmt.Errorf("%q", errs)
c.AbortWithStatusJSON(http.StatusInternalServerError, fmt.Errorf("%q", errs))
return
}
} else {
return nil, fmt.Errorf("%q", errs)
c.AbortWithStatusJSON(http.StatusInternalServerError, fmt.Errorf("%q", errs))
return
}
c.AbortWithStatusJSON(http.StatusInternalServerError, fmt.Errorf("%q", errs))
}