Ajouter route /v1 #16
1 changed files with 15 additions and 0 deletions
15
server.go
15
server.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"git.agecem.com/agecem/agecem-org/public"
|
"git.agecem.com/agecem/agecem-org/public"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
@ -38,6 +39,12 @@ func Execute() {
|
||||||
|
|
||||||
e.Pre(middleware.RemoveTrailingSlash())
|
e.Pre(middleware.RemoveTrailingSlash())
|
||||||
|
|
||||||
|
// API Routes
|
||||||
|
|
||||||
|
e.GET("/v1", handleV1)
|
||||||
|
|
||||||
|
// HTML Routes
|
||||||
|
|
||||||
e.GET("/", handleIndex)
|
e.GET("/", handleIndex)
|
||||||
|
|
||||||
e.Logger.Fatal(e.Start(":8080"))
|
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
|
// 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
|
// HTML Handlers
|
||||||
|
|
||||||
func handleIndex(c echo.Context) error {
|
func handleIndex(c echo.Context) error {
|
||||||
|
|
Loading…
Reference in a new issue