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 57)
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(
44 github_oauth_provider,
45 oauth_provider_rs::http_integration::config::OAuthProviderConfig::default(),
46 );
47
48 // Create custom routers
49 let health_router = Router::new().route("/health", get(health_check));
50
51 let api_router = Router::new().route("/status", get(api_status));
52
53 // Build microkernel server with custom routers
54 let microkernel: GitHubMicrokernelServer = MicrokernelServer::new()
55 .with_oauth_provider(oauth_provider)
56 .with_custom_router(health_router)
57 .with_custom_router_config(api_router, CustomRouterConfig::with_prefix("/api"));
58
59 // Test that the router can be built
60 let router = microkernel.build_router()?;
61 println!("✅ Router built successfully!");
62
63 // Print available endpoints
64 println!("\n📋 Server would have these endpoints:");
65 println!(" OAuth:");
66 println!(" GET /oauth/login");
67 println!(" GET /oauth/callback");
68 println!(" POST /oauth/token");
69 println!(" Custom:");
70 println!(" GET /health");
71 println!(" GET /api/status");
72
73 println!("\n🎉 Custom router functionality is working correctly!");
74 println!(" The server can be built and all routers are properly attached.");
75
76 Ok(())
77}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 153)
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").unwrap_or_else(|_| "demo_client_id".to_string()),
116 std::env::var("GITHUB_CLIENT_SECRET").unwrap_or_else(|_| "demo_client_secret".to_string()),
117 "http://localhost:8080/oauth/callback".to_string(),
118 "read:user".to_string(),
119 "github".to_string(),
120 );
121
122 let github_oauth_provider = GitHubOAuthProvider::new_github(github_config);
123 let oauth_provider = OAuthProvider::new(
124 github_oauth_provider,
125 oauth_provider_rs::http_integration::config::OAuthProviderConfig::default(),
126 );
127
128 // Create custom routers
129
130 // 1. Health and basic endpoints router
131 let health_router = Router::new()
132 .route("/health", get(health_check))
133 .route("/webhooks", post(webhook_handler));
134
135 // 2. Monitoring router with path prefix
136 let monitoring_router = Router::new().route("/metrics", get(metrics));
137
138 // 3. API router with versioned endpoints
139 let api_router = Router::new()
140 .route("/v1/status", get(api_status))
141 .route("/{version}/status", get(api_status));
142
143 // 4. Admin router with HTML interface
144 let admin_router = Router::new().route("/", get(admin_dashboard));
145
146 // Configure custom routers with different configurations
147 let custom_routers = vec![
148 // Health router without prefix (attached to root)
149 (health_router, CustomRouterConfig::default()),
150 // Monitoring router with prefix and name
151 (
152 monitoring_router,
153 CustomRouterConfig::with_name_and_prefix("Monitoring", "/monitoring"),
154 ),
155 // API router with prefix
156 (
157 api_router,
158 CustomRouterConfig::with_name_and_prefix("API", "/api"),
159 ),
160 // Admin router with prefix
161 (
162 admin_router,
163 CustomRouterConfig::with_name_and_prefix("Admin Dashboard", "/admin"),
164 ),
165 ];
166
167 // Build the microkernel server with OAuth provider and custom routers
168 let microkernel: GitHubMicrokernelServer = MicrokernelServer::new()
169 .with_oauth_provider(oauth_provider)
170 .with_custom_routers(custom_routers);
171
172 // Define the bind address
173 let bind_address: SocketAddr = "127.0.0.1:8080".parse()?;
174
175 // Print available endpoints
176 println!("🚀 Starting microkernel server with custom routers...");
177 println!("📍 Server listening on: http://{}", bind_address);
178 println!("\n📋 Available endpoints:");
179 println!(" OAuth:");
180 println!(" GET /oauth/login");
181 println!(" GET /oauth/callback");
182 println!(" POST /oauth/token");
183 println!(" Custom Endpoints:");
184 println!(" GET /health - Health check");
185 println!(" POST /webhooks - Webhook handler");
186 println!(" GET /monitoring/metrics - System metrics");
187 println!(" GET /api/v1/status - API status");
188 println!(" GET /api/{{version}}/status - Versioned API status");
189 println!(" GET /admin - Admin dashboard");
190 println!("\n🔧 Try these commands:");
191 println!(" curl http://localhost:8080/health");
192 println!(" curl http://localhost:8080/monitoring/metrics");
193 println!(" curl http://localhost:8080/api/v1/status");
194 println!(" open http://localhost:8080/admin");
195
196 // Start the server
197 microkernel.serve(bind_address).await?;
198
199 Ok(())
200}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.