sa-token-plugin-gotham
为 Gotham 框架提供 sa-token 认证和授权支持
Provides sa-token authentication and authorization support for Gotham framework
特性 | Features
- ✨ 一行导入所有功能 | One-line import for all functionalities
- 🔧 支持多种存储后端 | Support for multiple storage backends
- 🚀 简化的中间件集成 | Simplified middleware integration
- 📦 包含核心、宏、存储 | Includes core, macros, and storage
快速开始 | Quick Start
[dependencies]
sa-token-plugin-gotham = "0.1.5"
use sa_token_plugin_gotham::*;
use gotham::router::Router;
use gotham::pipeline::{new_pipeline, single_pipeline};
use std::sync::Arc;
#[tokio::main]
async fn main() {
let storage = Arc::new(MemoryStorage::new());
let state = SaTokenState::builder()
.storage(storage)
.timeout(7200)
.build();
let (chain, pipelines) = single_pipeline(
new_pipeline()
.add(SaTokenMiddleware::new(state.clone()))
.build()
);
let (chain, pipelines) = single_pipeline(
new_pipeline()
.add(SaCheckLoginMiddleware::new(state.clone()))
.build()
);
let (chain, pipelines) = single_pipeline(
new_pipeline()
.add(SaCheckPermissionMiddleware::new(state.clone(), "admin"))
.build()
);
let router = Router::new(chain, pipelines, |route| {
route.get("/api/user").to(user_handler);
route.get("/api/admin").to(admin_handler);
});
let addr = "127.0.0.1:8080";
gotham::start(addr, || Ok(router));
}