1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Author: 金书记
//
//! 忽略认证宏
use TokenStream;
use TokenStream as TokenStream2;
use quote;
use ;
/// 忽略认证检查的宏
///
/// 使用此宏标注的函数、结构体或impl块将跳过所有sa-token的认证检查,
/// 包括登录验证、权限验证、角色验证和路由拦截器。
///
/// 这对于公开API、健康检查接口等不需要认证的端点非常有用。
///
/// # 可以应用于
///
/// - 函数:单个路由处理函数忽略认证
/// - 结构体:整个控制器的所有方法都忽略认证
/// - impl块:impl块中的所有方法都忽略认证
///
/// # 示例
///
/// ## 在函数上使用
///
/// ```rust,ignore
/// #[sa_ignore]
/// async fn public_api() -> impl Responder {
/// // 此接口不需要任何认证
/// "Public API"
/// }
///
/// #[sa_ignore]
/// async fn health_check() -> impl Responder {
/// // 健康检查接口,无需认证
/// "OK"
/// }
/// ```
///
/// ## 在结构体上使用
///
/// ```rust,ignore
/// #[sa_ignore]
/// struct PublicController;
///
/// impl PublicController {
/// // 此控制器的所有方法都不需要认证
/// async fn home() -> impl Responder {
/// "Home page"
/// }
///
/// async fn about() -> impl Responder {
/// "About page"
/// }
/// }
/// ```
///
/// ## 在impl块上使用
///
/// ```rust,ignore
/// struct ApiController;
///
/// #[sa_ignore]
/// impl ApiController {
/// // 这个impl块中的所有方法都忽略认证
/// async fn version() -> impl Responder {
/// "v1.0.0"
/// }
/// }
/// ```
///
/// # 优先级
///
/// `#[sa_ignore]` 的优先级最高,即使同时使用了 `#[sa_check_login]` 等其他认证宏,
/// 也会被 `#[sa_ignore]` 覆盖,不进行任何认证检查。
///
/// ```rust,ignore
/// // 警告:sa_ignore 会覆盖 sa_check_login
/// #[sa_ignore]
/// #[sa_check_login] // 这个会被忽略
/// async fn example() -> impl Responder {
/// // 实际上不会进行登录检查
/// "Example"
/// }
/// ```