pub struct Server { /* private fields */ }Expand description
Web 服务器
Implementations§
Source§impl Server
impl Server
Sourcepub async fn run<F>(configure: F) -> AppResult<()>
pub async fn run<F>(configure: F) -> AppResult<()>
启动服务器(使用闭包配置方式)
§参数
configure: 配置闭包,接收 ServerBuilder 用于配置路由
§示例
use fbc_starter::{Config, Server};
use axum::{routing::get, Router};
Server::run(|builder| {
// 获取配置
let config = builder.config();
// 配置 HTTP 路由
let http_router = Router::new()
.route("/api/users", get(|| async { "users" }));
// 配置 gRPC 路由(如果启用)
#[cfg(feature = "grpc")]
let grpc_router = tonic::transport::Server::builder()
.add_service(MyServiceServer::new(MyServiceImpl));
builder
.http_router(http_router)
#[cfg(feature = "grpc")]
.grpc_router(grpc_router)
}).await?;Sourcepub async fn run_with_config<F>(config: Config, configure: F) -> AppResult<()>
pub async fn run_with_config<F>(config: Config, configure: F) -> AppResult<()>
Auto Trait Implementations§
impl Freeze for Server
impl !RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl !UnwindSafe for Server
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