Merge pull request 'Ajouter route /v1' (#16) from feature/route-v1 into main

Reviewed-on: #16
This commit is contained in:
Victor Lacasse-Beaudoin 2023-03-21 17:49:44 -05:00
commit ebf5837f5c

View file

@ -5,6 +5,7 @@ import (
"html/template"
"io"
"net/http"
"sort"
"git.agecem.com/agecem/agecem-org/public"
"github.com/labstack/echo/v4"
@ -38,6 +39,12 @@ func Execute() {
e.Pre(middleware.RemoveTrailingSlash())
// API Routes
e.GET("/v1", handleV1)
// HTML Routes
e.GET("/", handleIndex)
e.Logger.Fatal(e.Start(":8080"))
@ -49,6 +56,14 @@ func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Con
// API Handlers
// handleV1 affiche les routes accessibles.
// Les routes sont triées selon .Path, pour les rendre plus facilement navigables.
func handleV1(c echo.Context) error {
routes := c.Echo().Routes()
sort.Slice(routes, func(i, j int) bool { return routes[i].Path < routes[j].Path })
return c.JSON(http.StatusOK, routes)
}
// HTML Handlers
func handleIndex(c echo.Context) error {