pub struct CustomRouterConfig {
pub name: Option<String>,
pub path_prefix: Option<String>,
}Expand description
Configuration for custom router attachment
Fields§
§name: Option<String>Optional name for the custom router (for logging/debugging)
path_prefix: Option<String>Optional path prefix for the router
Implementations§
Source§impl CustomRouterConfig
impl CustomRouterConfig
Sourcepub fn with_name(name: impl Into<String>) -> Self
pub fn with_name(name: impl Into<String>) -> Self
Create a new custom router configuration with a name
Sourcepub fn with_prefix(path_prefix: impl Into<String>) -> Self
pub fn with_prefix(path_prefix: impl Into<String>) -> Self
Create a new custom router configuration with a path prefix
Examples found in repository?
examples/simple_custom_router_test.rs (line 54)
30async fn main() -> Result<(), Box<dyn std::error::Error>> {
31 println!("🧪 Testing custom router functionality...");
32
33 // Create OAuth provider
34 let github_config = OAuthProviderConfig::with_oauth_config(
35 "test_client_id".to_string(),
36 "test_client_secret".to_string(),
37 "http://localhost:8080/oauth/callback".to_string(),
38 "read:user".to_string(),
39 "github".to_string(),
40 );
41
42 let github_oauth_provider = GitHubOAuthProvider::new_github(github_config);
43 let oauth_provider = OAuthProvider::new(github_oauth_provider, oauth_provider_rs::http_integration::config::OAuthProviderConfig::default());
44
45 // Create custom routers
46 let health_router = Router::new().route("/health", get(health_check));
47
48 let api_router = Router::new().route("/status", get(api_status));
49
50 // Build microkernel server with custom routers
51 let microkernel: GitHubMicrokernelServer = MicrokernelServer::new()
52 .with_oauth_provider(oauth_provider)
53 .with_custom_router(health_router)
54 .with_custom_router_config(api_router, CustomRouterConfig::with_prefix("/api"));
55
56 // Test that the router can be built
57 let router = microkernel.build_router()?;
58 println!("✅ Router built successfully!");
59
60 // Print available endpoints
61 println!("\n📋 Server would have these endpoints:");
62 println!(" OAuth:");
63 println!(" GET /oauth/login");
64 println!(" GET /oauth/callback");
65 println!(" POST /oauth/token");
66 println!(" Custom:");
67 println!(" GET /health");
68 println!(" GET /api/status");
69
70 println!("\n🎉 Custom router functionality is working correctly!");
71 println!(" The server can be built and all routers are properly attached.");
72
73 Ok(())
74}Sourcepub fn with_name_and_prefix(
name: impl Into<String>,
path_prefix: impl Into<String>,
) -> Self
pub fn with_name_and_prefix( name: impl Into<String>, path_prefix: impl Into<String>, ) -> Self
Create a new custom router configuration with both name and path prefix
Examples found in repository?
examples/custom_router_example.rs (line 152)
109async fn main() -> Result<(), Box<dyn std::error::Error>> {
110 // Initialize tracing for logging
111 tracing_subscriber::fmt::init();
112
113 // Create GitHub OAuth provider
114 let github_config = OAuthProviderConfig::with_oauth_config(
115 std::env::var("GITHUB_CLIENT_ID")
116 .unwrap_or_else(|_| "demo_client_id".to_string()),
117 std::env::var("GITHUB_CLIENT_SECRET")
118 .unwrap_or_else(|_| "demo_client_secret".to_string()),
119 "http://localhost:8080/oauth/callback".to_string(),
120 "read:user".to_string(),
121 "github".to_string(),
122 );
123
124 let github_oauth_provider = GitHubOAuthProvider::new_github(github_config);
125 let oauth_provider = OAuthProvider::new(github_oauth_provider, oauth_provider_rs::http_integration::config::OAuthProviderConfig::default());
126
127 // Create custom routers
128
129 // 1. Health and basic endpoints router
130 let health_router = Router::new()
131 .route("/health", get(health_check))
132 .route("/webhooks", post(webhook_handler));
133
134 // 2. Monitoring router with path prefix
135 let monitoring_router = Router::new().route("/metrics", get(metrics));
136
137 // 3. API router with versioned endpoints
138 let api_router = Router::new()
139 .route("/v1/status", get(api_status))
140 .route("/{version}/status", get(api_status));
141
142 // 4. Admin router with HTML interface
143 let admin_router = Router::new().route("/", get(admin_dashboard));
144
145 // Configure custom routers with different configurations
146 let custom_routers = vec![
147 // Health router without prefix (attached to root)
148 (health_router, CustomRouterConfig::default()),
149 // Monitoring router with prefix and name
150 (
151 monitoring_router,
152 CustomRouterConfig::with_name_and_prefix("Monitoring", "/monitoring"),
153 ),
154 // API router with prefix
155 (
156 api_router,
157 CustomRouterConfig::with_name_and_prefix("API", "/api"),
158 ),
159 // Admin router with prefix
160 (
161 admin_router,
162 CustomRouterConfig::with_name_and_prefix("Admin Dashboard", "/admin"),
163 ),
164 ];
165
166 // Build the microkernel server with OAuth provider and custom routers
167 let microkernel: GitHubMicrokernelServer = MicrokernelServer::new()
168 .with_oauth_provider(oauth_provider)
169 .with_custom_routers(custom_routers);
170
171 // Define the bind address
172 let bind_address: SocketAddr = "127.0.0.1:8080".parse()?;
173
174 // Print available endpoints
175 println!("🚀 Starting microkernel server with custom routers...");
176 println!("📍 Server listening on: http://{}", bind_address);
177 println!("\n📋 Available endpoints:");
178 println!(" OAuth:");
179 println!(" GET /oauth/login");
180 println!(" GET /oauth/callback");
181 println!(" POST /oauth/token");
182 println!(" Custom Endpoints:");
183 println!(" GET /health - Health check");
184 println!(" POST /webhooks - Webhook handler");
185 println!(" GET /monitoring/metrics - System metrics");
186 println!(" GET /api/v1/status - API status");
187 println!(" GET /api/{{version}}/status - Versioned API status");
188 println!(" GET /admin - Admin dashboard");
189 println!("\n🔧 Try these commands:");
190 println!(" curl http://localhost:8080/health");
191 println!(" curl http://localhost:8080/monitoring/metrics");
192 println!(" curl http://localhost:8080/api/v1/status");
193 println!(" open http://localhost:8080/admin");
194
195 // Start the server
196 microkernel.serve(bind_address).await?;
197
198 Ok(())
199}Trait Implementations§
Source§impl Clone for CustomRouterConfig
impl Clone for CustomRouterConfig
Source§fn clone(&self) -> CustomRouterConfig
fn clone(&self) -> CustomRouterConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CustomRouterConfig
impl Debug for CustomRouterConfig
Auto Trait Implementations§
impl Freeze for CustomRouterConfig
impl RefUnwindSafe for CustomRouterConfig
impl Send for CustomRouterConfig
impl Sync for CustomRouterConfig
impl Unpin for CustomRouterConfig
impl UnwindSafe for CustomRouterConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.