From 0b38c9a0ed5485d2a3e7df1360984f46569c2cc4 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Tue, 21 Mar 2023 18:48:23 -0400 Subject: [PATCH] Ajouter route /v1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Permet de lister les différentes routes (html et json) disponibles. --- server.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server.go b/server.go index 5f67ef0..93861fe 100644 --- a/server.go +++ b/server.go @@ -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 { -- 2.45.2