Skip to main content

alun_web/
lib.rs

1//! Alun web layer: 路由、中间件、提取器、响应、全局资源
2
3pub mod app;
4pub mod router;
5pub mod middleware;
6pub mod jwt;
7pub mod response;
8pub mod extract;
9pub mod resources;
10
11pub use app::App;
12pub use router::AlunRouter;
13pub use response::{Res, ResResult, ApiError, PageData};
14pub use middleware::{UserId, AuthClaims, AuthLayer, RequireRoleLayer, RequirePermissionLayer, TokenClaims, TokenType};
15pub use jwt::JWT;
16pub use extract::ValidatedJson;
17
18#[cfg(feature = "db")]
19pub use crate::resources::{db, try_db, set_db};
20#[cfg(feature = "cache")]
21pub use crate::resources::{cache, try_cache, set_cache};
22pub use crate::resources::{cfg, config, try_config, set_config};
23#[cfg(feature = "template")]
24pub use crate::resources::{render_template, try_template, set_template};
25pub use crate::resources::{
26    set_upload_path, upload_path, try_upload_path,
27    set_download_path, download_path, try_download_path,
28};
29
30/// 路由注册分布式切片 —— `#[get]`、`#[post]` 等宏注解的处理器在此汇集
31#[linkme::distributed_slice]
32pub static ROUTES: [fn(&mut AlunRouter)] = [..];
33
34/// 路径权限定义 —— 由 `#[permission("xxx")]` 宏注解生成
35///
36/// 每条记录描述一个接口路径所需的权限标识。
37/// 运行时通过 `PermissionCheckLayer` 中间件校验。
38#[derive(Debug, Clone)]
39pub struct PermissionDef {
40    /// URL 路径
41    pub path: &'static str,
42    /// HTTP 方法
43    pub method: &'static str,
44    /// 所需权限标识
45    pub permission: &'static str,
46}
47
48/// 路径权限分布式切片 —— `#[permission]` 宏注解的权限规则在此汇集
49#[linkme::distributed_slice]
50pub static PERMISSION_ROUTES: [PermissionDef] = [..];
51
52/// 无需认证的路径定义 —— 由 `#[no_auth]` 宏注解生成
53///
54/// 在路径列表中指定的接口将绕过 AuthLayer 中间件。
55#[derive(Debug, Clone)]
56pub struct NoAuthDef {
57    /// URL 路径
58    pub path: &'static str,
59}
60
61/// 无需认证路径分布式切片 —— `#[no_auth]` 宏注解的路径在此汇集
62#[linkme::distributed_slice]
63pub static NO_AUTH_ROUTES: [NoAuthDef] = [..];