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:
22
internal/routes/routes.go
Normal file
22
internal/routes/routes.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user