Extract routes to getRoutes() function
All checks were successful
CI / build (push) Successful in 26s

Address review feedback to eliminate duplicated route configuration
and prevent potential inconsistencies.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit was merged in pull request #20.
This commit is contained in:
2026-01-09 17:24:09 +01:00
parent 3bd0659caf
commit 9b83333275

View File

@@ -65,9 +65,20 @@ func main() {
handleOAuthCallback() handleOAuthCallback()
return return
} }
router := navigation.NewRouter(getRoutes())
router.SetNotFoundHandler(notFoundView)
navigation.SetGlobalRouter(router)
// Set up routes // Create the main app with router
routes := []navigation.Route{ ui.NewAppWithRouter(router)
// Keep the application running
select {}
}
// getRoutes returns the route configuration for the application
func getRoutes() []navigation.Route {
return []navigation.Route{
{ {
Path: "/", Path: "/",
Handler: homeView, Handler: homeView,
@@ -87,16 +98,6 @@ func main() {
Guards: []navigation.RouteGuard{authGuard()}, Guards: []navigation.RouteGuard{authGuard()},
}, },
} }
router := navigation.NewRouter(routes)
router.SetNotFoundHandler(notFoundView)
navigation.SetGlobalRouter(router)
// Create the main app with router
ui.NewAppWithRouter(router)
// Keep the application running
select {}
} }
// checkExistingSession checks for existing valid tokens // checkExistingSession checks for existing valid tokens
@@ -150,28 +151,7 @@ func handleOAuthCallback() {
// renderApp initializes and renders the app after callback processing // renderApp initializes and renders the app after callback processing
func renderApp() { func renderApp() {
routes := []navigation.Route{ router := navigation.NewRouter(getRoutes())
{
Path: "/",
Handler: homeView,
},
{
Path: "/callback",
Handler: callbackView,
},
{
Path: "/profile",
Handler: profileView,
Guards: []navigation.RouteGuard{authGuard()},
},
{
Path: "/protected",
Handler: protectedView,
Guards: []navigation.RouteGuard{authGuard()},
},
}
router := navigation.NewRouter(routes)
router.SetNotFoundHandler(notFoundView) router.SetNotFoundHandler(notFoundView)
navigation.SetGlobalRouter(router) navigation.SetGlobalRouter(router)