Struct CustomRouterConfig

Source
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

Source

pub fn with_name(name: impl Into<String>) -> Self

Create a new custom router configuration with a name

Source

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}
Source

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

Source§

fn clone(&self) -> CustomRouterConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CustomRouterConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CustomRouterConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,