refactor routing into a modular and versioned structure

Move inline route definitions from main.go into a dedicated internal/routes package. This organization introduces support for API versioning (v1) and separates endpoint logic into specialized modules for administration and bug reporting.
This commit is contained in:
Flavio Fois
2026-03-23 09:18:16 +01:00
parent 9aa188af8c
commit 84521d8d59
5 changed files with 136 additions and 76 deletions

22
internal/routes/routes.go Normal file
View File

@@ -0,0 +1,22 @@
package routes
import (
"net/http"
v1 "emly-api-go/internal/routes/v1"
"github.com/go-chi/chi/v5"
"github.com/jmoiron/sqlx"
)
// RegisterAll mounts every versioned API onto the root router.
// To add a new API version, create internal/routes/v2 and add:
//
// r.Mount("/v2", v2.NewRouter(db))
func RegisterAll(r chi.Router, db *sqlx.DB) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("emly-api-go"))
})
r.Mount("/v1", v1.NewRouter(db))
}