sa_token_plugin_gotham/
lib.rs

1// Author: 金书记
2//
3// 中文 | English
4// Gotham 框架集成 | Gotham Framework Integration
5//
6//! # sa-token-plugin-gotham
7//! 
8//! 为 Gotham 框架提供 sa-token 认证和授权支持
9//! Provides sa-token authentication and authorization support for Gotham 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-gotham = "0.1.5"
23//! ```
24//! 
25//! ```rust,ignore
26//! use sa_token_plugin_gotham::*;
27//! use gotham::router::Router;
28//! use gotham::pipeline::{new_pipeline, single_pipeline};
29//! use std::sync::Arc;
30//! 
31//! #[tokio::main]
32//! async fn main() {
33//!     let storage = Arc::new(MemoryStorage::new());
34//!     let state = SaTokenState::builder()
35//!         .storage(storage)
36//!         .timeout(7200)
37//!         .build();
38//!     
39//!     // 方式1:使用基础中间件 + 手动检查
40//!     let (chain, pipelines) = single_pipeline(
41//!         new_pipeline()
42//!             .add(SaTokenMiddleware::new(state.clone()))
43//!             .build()
44//!     );
45//!     
46//!     // 方式2:使用登录检查中间件
47//!     let (chain, pipelines) = single_pipeline(
48//!         new_pipeline()
49//!             .add(SaCheckLoginMiddleware::new(state.clone()))
50//!             .build()
51//!     );
52//!     
53//!     // 方式3:使用权限检查中间件
54//!     let (chain, pipelines) = single_pipeline(
55//!         new_pipeline()
56//!             .add(SaCheckPermissionMiddleware::new(state.clone(), "admin"))
57//!             .build()
58//!     );
59//!     
60//!     let router = Router::new(chain, pipelines, |route| {
61//!         route.get("/api/user").to(user_handler);
62//!         route.get("/api/admin").to(admin_handler);
63//!     });
64//!     
65//!     let addr = "127.0.0.1:8080";
66//!     gotham::start(addr, || Ok(router));
67//! }
68//! ```
69
70pub mod adapter;
71pub mod extractor;
72pub mod middleware;
73pub mod layer;
74pub mod state;
75pub mod wrapper;
76
77pub use sa_token_core::{self, prelude::*};
78pub use sa_token_adapter::{self, storage::SaStorage, framework::FrameworkAdapter};
79pub use sa_token_macro::*;
80
81// 重新导出存储实现(通过 feature 控制)
82// Re-export storage implementations (controlled by features)
83#[cfg(feature = "memory")]
84pub use sa_token_storage_memory::*;
85
86#[cfg(feature = "redis")]
87pub use sa_token_storage_redis::*;
88
89#[cfg(feature = "database")]
90pub use sa_token_storage_database::*;
91
92// 重新导出本模块的适配器 | Re-export adapters from this module
93pub use adapter::*;
94pub use extractor::*;
95pub use middleware::*;
96pub use layer::SaTokenLayer;
97pub use state::{SaTokenState, SaTokenStateBuilder};
98pub use wrapper::{TokenValueWrapper, LoginIdWrapper};
99