Ajouter route /v1
Permet de lister les différentes routes (html et json) disponibles.
This commit is contained in:
parent
ed61eee763
commit
0b38c9a0ed
1 changed files with 15 additions and 0 deletions
15
server.go
15
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 {
|
||||
|
|
Loading…
Reference in a new issue