A clean and extensible demonstration of routing architecture using echo/v4 for Go.
This repository showcases a declarative, domain-driven routing design intended for scalable and maintainable web applications.
Routes are defined as data, not code. Instead of calling e.GET() or e.POST() directly for every route, all route information is declared in structured types and registered centrally.
type Route struct {
Method string
Path string
Handler echo.HandlerFunc
Middlewares []echo.MiddlewareFunc
}Each domain exposes a function returning a RouteGroup:
type RouteGroup struct {
Prefix string
Routes []Route
}This allows the routing logic to stay simple, testable, and easy to maintain.
Each logical module (domain) defines its own routes in isolation, using a consistent and pluggable structure:
type RouteGroupFunc func(handler.Handler) RouteGroupIn main.go (or wherever routes are wired), all domain modules can be registered like this:
router.RegisterRoutes(
TicketRoutes,
BackfillRoutes,
)All routes are ultimately registered via a central Router that encapsulates the Echo instance and handler dependencies:
r.e.Add(route.Method, routeGroup.Prefix+route.Path, route.Handler, route.Middlewares...).
├── cmd/
│ └── main.go # Main entry point
├── handler/ # Business logic handlers
├── route/ # Route definitions per domain
├── router/ # Router orchestrator
└── server/ # Server initialization and run
- Separation of concerns between handler logic and routing structure
- Easily testable route declarations
- Declarative and extendable design
- Minimal boilerplate when adding new endpoints
- Ready for middleware injection, versioning, and Swagger integration
- Go 1.18+
- Echo v4