sa_token_plugin_tide/lib.rs
1// Author: 金书记
2//
3// 中文 | English
4// Tide 框架集成 | Tide Framework Integration
5//
6//! # sa-token-plugin-tide
7//!
8//! 为 Tide 框架提供 sa-token 认证和授权支持
9//! Provides sa-token authentication and authorization support for Tide framework
10//!
11//! ## 特性 | Features
12//!
13//! - ✨ 一行导入所有功能 | One-line import for all functionalities
14//! - 🔧 支持多种存储后端 | Support for multiple storage backends
15//! - 🚀 简化的中间件集成 | Simplified middleware integration
16//! - 📦 包含核心、宏、存储 | Includes core, macros, and storage
17//!
18//! ## 快速开始 | Quick Start
19//!
20//! ```toml
21//! [dependencies]
22//! sa-token-plugin-tide = "0.1.8"
23//! ```
24//!
25//! ```rust,ignore
26//! use std::sync::Arc;
27//! use sa_token_plugin_tide::*;
28//!
29//! #[async_std::main]
30//! async fn main() -> tide::Result<()> {
31//! let storage = Arc::new(MemoryStorage::new());
32//!
33//! // 创建 Sa-Token 状态 | Create Sa-Token state
34//! let state = SaTokenState::builder()
35//! .token_name("Authorization")
36//! .timeout(7200)
37//! .storage(storage)
38//! .build();
39//!
40//! let mut app = tide::new();
41//!
42//! // 公共路由 | Public routes
43//! app.at("/login").post(login_handler);
44//!
45//! // 需要登录的路由 | Routes requiring login
46//! app.at("/user")
47//! .with(SaCheckLoginMiddleware::new(state.clone()))
48//! .get(user_info_handler);
49//!
50//! // 需要特定权限的路由 | Routes requiring specific permission
51//! app.at("/admin")
52//! .with(SaCheckPermissionMiddleware::new(state.clone(), "admin:access"))
53//! .get(admin_handler);
54//!
55//! app.listen("127.0.0.1:8080").await?;
56//! Ok(())
57//! }
58//! ```
59
60pub mod adapter;
61pub mod extractor;
62pub mod middleware;
63pub mod layer;
64pub mod state;
65
66pub use sa_token_core::{self, prelude::*};
67pub use sa_token_adapter::{self, storage::SaStorage, framework::FrameworkAdapter};
68pub use sa_token_macro::*;
69
70// 重新导出存储实现(通过 feature 控制)
71// Re-export storage implementations (controlled by features)
72#[cfg(feature = "memory")]
73pub use sa_token_storage_memory::*;
74
75#[cfg(feature = "redis")]
76pub use sa_token_storage_redis::*;
77
78#[cfg(feature = "database")]
79pub use sa_token_storage_database::*;
80
81// 重新导出本模块的适配器 | Re-export adapters from this module
82pub use adapter::*;
83pub use extractor::*;
84pub use middleware::{
85 AuthMiddleware, PermissionMiddleware,
86 SaCheckLoginMiddleware, SaCheckPermissionMiddleware, SaCheckRoleMiddleware
87};
88pub use layer::{SaTokenLayer, extract_token_from_request};
89pub use state::{SaTokenState, SaTokenStateBuilder};
90