Routing
Andurel keeps route declarations separate from controller registration and provides typed URL helpers for application links via github.com/mbvlabs/andurel/pkg/routing.
Declare a route
Generated files in router/routes declare route values. The router binds them to controllers and middleware.
1import "github.com/mbvlabs/andurel/pkg/routing"
2
3var ProductShow = routing.NewRouteWithUUIDID(
4 "/products/:id",
5 "products.show",
6 "",
7 routing.InertiaRoute(),
8)
Path() returns the Echo registration path, Name() returns the name, URL(...) substitutes typed parameters, and FullURL(base, ...) prepends the application base URL. Use InertiaRoute() when the route should appear in generated TypeScript helpers.
Use the helper instead of hard-coding an application URL:
1routes.ProductShow.URL(product.ID)
Typed parameter routes
| Constructor | Placeholder | Go argument |
|---|---|---|
NewSimpleRoute |
none | none |
NewRouteWithUUIDID |
:id |
uuid.UUID |
NewRouteWithSerialID |
:id |
int32 |
NewRouteWithBigSerialID |
:id |
int64 |
NewRouteWithStringID |
:id |
string |
NewRouteWithSlug |
:slug |
string |
NewRouteWithToken |
:token |
string |
NewRouteWithParams[T] |
tagged fields | typed struct |
Multiple parameters use a struct so call sites cannot swap same-typed values:
1type ProjectParams struct {
2 Team string `param:"team"`
3 Project string `param:"project"`
4}
5var ProjectShow = routing.NewRouteWithParams[ProjectParams](
6 "/:team/projects/:project", "show", "projects",
7)
8url := ProjectShow.URL(ProjectParams{Team: "platform", Project: "orbit"})
Register a handler
Controllers register Echo routes with the application router:
1_, err := r.AddRoute(echo.Route{
2 Method: http.MethodGet,
3 Path: routes.ProductShow.Path(),
4 Name: routes.ProductShow.Name(),
5 Handler: products.Show,
6})
The router and controllers are Fx modules. Dependencies are constructor parameters; do not store them in an Echo or standard-library context.
Inspect and export routes
1andurel inspect routes --json
2andurel sync routes
The manifest reports route names, paths, parameters, and source locations. In Inertia projects, sync routes writes resources/js/routes.ts. See TypeScript Sync.