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;
17pub use extract::{validate_uuid, validate_mobile, validate_password_strength, validate_id_card, validate_date, validate_email, validate_url, validate_datetime, validate_date_or_datetime};
18pub use extract::ValidateExt;
19
20#[cfg(feature = "db")]
21pub use crate::resources::{db, try_db, set_db};
22#[cfg(feature = "cache")]
23pub use crate::resources::{cache, try_cache, set_cache};
24pub use crate::resources::{cfg, config, try_config, set_config};
25#[cfg(feature = "template")]
26pub use crate::resources::{render_template, try_template, set_template};
27pub use crate::resources::{
28    set_upload_path, upload_path, try_upload_path,
29    set_download_path, download_path, try_download_path,
30};
31
32/// 路由注册分布式切片 —— `#[get]`、`#[post]` 等宏注解的处理器在此汇集
33#[linkme::distributed_slice]
34pub static ROUTES: [fn(&mut AlunRouter)] = [..];
35
36/// 路径权限定义 —— 由 `#[permission("xxx")]` 宏注解生成
37///
38/// 每条记录描述一个接口路径所需的权限标识。
39/// 运行时通过 `PermissionCheckLayer` 中间件校验。
40#[derive(Debug, Clone)]
41pub struct PermissionDef {
42    /// URL 路径
43    pub path: &'static str,
44    /// HTTP 方法
45    pub method: &'static str,
46    /// 所需权限标识
47    pub permission: &'static str,
48}
49
50/// 路径权限分布式切片 —— `#[permission]` 宏注解的权限规则在此汇集
51#[linkme::distributed_slice]
52pub static PERMISSION_ROUTES: [PermissionDef] = [..];
53
54/// 无需认证的路径定义 —— 由 `#[no_auth]` 宏注解生成
55///
56/// 在路径列表中指定的接口将绕过 AuthLayer 中间件。
57#[derive(Debug, Clone)]
58pub struct NoAuthDef {
59    /// URL 路径
60    pub path: &'static str,
61}
62
63/// 无需认证路径分布式切片 —— `#[no_auth]` 宏注解的路径在此汇集
64#[linkme::distributed_slice]
65pub static NO_AUTH_ROUTES: [NoAuthDef] = [..];