From f2e666874dec0c52a08358ecb9dea16e10d9b79e Mon Sep 17 00:00:00 2001 From: grngxd <36968271+grngxd@users.noreply.github.com> Date: Mon, 5 May 2025 14:06:15 +0100 Subject: [PATCH] feat: registered file based routing --- internal/api/api.go | 22 ++++------------------ internal/api/routes/ping.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) create mode 100644 internal/api/routes/ping.go diff --git a/internal/api/api.go b/internal/api/api.go index a5eee16..874dbec 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -1,26 +1,12 @@ package api import ( - "net/http" - - "github.com/gin-gonic/gin" + "stereo.cat/backend/internal/api/routes" "stereo.cat/backend/internal/types" ) -func Register(cfg *types.StereoConfig) []types.Route { - routes := []types.Route{ - { - Path: "/ping", - Method: http.MethodGet, - Exec: func(cfg *types.StereoConfig) gin.HandlerFunc { - return func(c *gin.Context) { - c.String(http.StatusOK, "Pong!") - } - }, - }, - } +func Register(cfg *types.StereoConfig) { + api := cfg.Router.Group("/api") - types.RegisterRoutes("/api", routes, cfg) - - return routes + routes.RegisterPingRoutes(api) } diff --git a/internal/api/routes/ping.go b/internal/api/routes/ping.go new file mode 100644 index 0000000..b3289c1 --- /dev/null +++ b/internal/api/routes/ping.go @@ -0,0 +1,13 @@ +package routes + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func RegisterPingRoutes(api *gin.RouterGroup) { + api.GET("/ping", func(c *gin.Context) { + c.String(http.StatusOK, "Pong!") + }) +}