swan_common/types/
args.rs

1use syn::punctuated::Punctuated;
2use syn::{LitStr, Path, Token};
3use crate::types::http::{HttpMethod, ContentType};
4use crate::types::retry::RetryConfig;
5use crate::types::proxy::ProxyConfig;
6
7/// HTTP 处理器参数配置
8pub struct HandlerArgs {
9    pub url: LitStr,
10    pub method: HttpMethod,
11    pub content_type: Option<ContentType>,
12    pub headers: Punctuated<LitStr, Token![,]>,
13    pub interceptor: Option<Path>,
14    pub retry: Option<RetryConfig>,
15    pub proxy: Option<ProxyConfig>,
16}
17
18/// HTTP 客户端参数配置
19pub struct HttpClientArgs {
20    pub base_url: Option<LitStr>,
21    pub interceptor: Option<Path>,
22    pub state: Option<Path>,
23    pub proxy: Option<ProxyConfig>,
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use syn::LitStr;
30    use proc_macro2::Span;
31
32    #[test]
33    fn test_handler_args_creation() {
34        let url = LitStr::new("/test", Span::call_site());
35        let headers = Punctuated::new();
36        
37        let args = HandlerArgs {
38            url,
39            method: HttpMethod::Get,
40            content_type: Some(ContentType::Json),
41            headers,
42            interceptor: None,
43            retry: None,
44            proxy: None,
45        };
46
47        assert_eq!(args.method, HttpMethod::Get);
48        assert_eq!(args.url.value(), "/test");
49        assert_eq!(args.content_type, Some(ContentType::Json));
50    }
51
52    #[test]
53    fn test_http_client_args_creation() {
54        let base_url = Some(LitStr::new("https://api.example.com", Span::call_site()));
55        
56        let args = HttpClientArgs {
57            base_url,
58            interceptor: None,
59            state: None,
60            proxy: None,
61        };
62
63        assert!(args.base_url.is_some());
64        assert_eq!(args.base_url.unwrap().value(), "https://api.example.com");
65    }
66}