Upgrade Echo framework from v4 to v5

This commit is contained in:
2026-05-20 21:56:06 +02:00
parent 12f18ba12c
commit 2cff8d16d7
7 changed files with 53 additions and 51 deletions
+7 -8
View File
@@ -8,9 +8,8 @@ import (
"strings"
"github.com/a-h/templ"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/swaggo/echo-swagger"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
)
// @Title MusicServer API
@@ -34,7 +33,7 @@ func (s *Server) RegisterRoutes() http.Handler {
w.Header().Set("Content-Type", "application/json")
http.ServeFile(w, r, "cmd/docs/swagger.json")
})))
e.Use(middleware.Logger())
e.Use(middleware.RequestLogger())
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
@@ -53,8 +52,8 @@ func (s *Server) RegisterRoutes() http.Handler {
e.Static("/", "/frontend")
// Swagger UI
e.GET("/swagger/*", echoSwagger.WrapHandler)
// Swagger UI - TODO: Update for Echo v5
// e.GET("/swagger/*", echoSwagger.WrapHandler)
index := NewIndexHandler()
e.GET("/version", index.GetVersion)
@@ -98,13 +97,13 @@ func (s *Server) RegisterRoutes() http.Handler {
musicGroup.GET("/addQue", music.AddLatestToQue)
musicGroup.GET("/addPlayed", music.AddLatestPlayed)
routes := e.Routes()
routes := e.Router().Routes()
sort.Slice(routes, func(i, j int) bool {
return routes[i].Path < routes[j].Path
})
for _, r := range routes {
if (r.Method == "GET" || r.Method == "POST" || r.Method == "PUT" || r.Method == "DELETE") && !strings.Contains(r.Name, "github") {
fmt.Printf(" %s %s\n", r.Method, r.Path)
fmt.Printf(" %s\t\t%s\n", r.Method, r.Path)
}
}
return e