ferryman_core/lib.rs
1//! ferryman-core — routing table, per-upstream circuit breaker, active
2//! health checker, and TOML config schema.
3//!
4//! The server crate wires these primitives together behind a hyper service.
5//! Everything in this crate is reload-safe: `SharedTable` is an
6//! `Arc<ArcSwap<RouteTable>>` so a new table can be hot-swapped in without
7//! touching live connections.
8//!
9//! ```
10//! use ferryman_core::{build_table, ConfigToml};
11//!
12//! let cfg: ConfigToml = toml::from_str(r#"
13//! [[routes]]
14//! prefix = "/svc-a"
15//! upstream = "http://127.0.0.1:8001"
16//! "#)?;
17//! let table = build_table(cfg, None)?;
18//!
19//! let route = table.lookup("/svc-a/users").expect("route");
20//! assert!(table.lookup("/svc-ab").is_none());
21//! if let Some(ticket) = route.upstream.try_acquire() {
22//! // ... forward the request, then report the outcome:
23//! route.upstream.record_success(ticket);
24//! } else {
25//! // circuit open: answer 503
26//! }
27//! # Ok::<(), Box<dyn std::error::Error>>(())
28//! ```
29
30mod breaker;
31pub mod config;
32mod error;
33pub mod health;
34pub mod path;
35mod proxies;
36pub mod route;
37
38pub use breaker::{Breaker, BreakerConfig, CircuitState};
39pub use config::{build_table, load_config, ConfigToml, RouteToml, XffMode};
40pub use error::Error;
41pub use health::health_loop;
42pub use proxies::TrustedProxies;
43pub use route::{Admission, Route, RouteTable, SharedTable, Upstream};