nacos_rs_sdk/model.rs
1pub mod config;
2pub mod instance;
3pub mod nacos;
4
5// use async_trait::async_trait;
6use lazy_static::lazy_static;
7// use reqwest::{Client, Response};
8use reqwest::Client;
9// use serde::Serialize;
10// use std::error::Error;
11// use std::sync::{Arc, RwLock};
12// use std::time::Duration;
13
14// use crate::client::NacosClient;
15
16lazy_static! {
17 pub(crate) static ref CLIENT: Client = Client::new();
18}
19
20// pub trait Nacos {
21// fn get_token(&self) -> String;
22// fn get_nacos(&self) -> NacosClient;
23// fn clone_nacos(&self) -> Arc<RwLock<NacosClient>>;
24// fn set_nacos(&mut self, nacos: &Arc<RwLock<NacosClient>>);
25// }
26
27// #[async_trait]
28pub trait Get {
29 const URI: &'static str = "/";
30
31 fn get_uri(&self) -> &'static str {
32 Self::URI
33 }
34 // async fn get(&self) -> Result<Response, Box<dyn Error + Send + Sync>>
35 // where
36 // Self: Serialize,
37 // {
38 // let nacos = NacosClient::info();
39 // let token = nacos.get_token();
40 // let res = if token == "" {
41 // CLIENT.get(nacos.addr(Self::URI)).query(&self)
42 // } else {
43 // CLIENT
44 // .get(nacos.addr(Self::URI))
45 // .query(&[("accessToken", token)])
46 // .query(&self)
47 // }
48 // .timeout(Duration::from_secs(10));
49 // let resp = res.send().await?;
50 // Ok(resp)
51 // }
52}
53
54// #[async_trait]
55pub trait Post {
56 const URI: &'static str = "/";
57
58 fn post_uri(&self) -> &'static str {
59 Self::URI
60 }
61 // async fn post(&self) -> Result<Response, Box<dyn Error + Send + Sync>>
62 // where
63 // Self: Serialize,
64 // {
65 // let nacos = NacosClient::info();
66 // let token = nacos.get_token();
67 // let res = if token == "" {
68 // CLIENT.post(nacos.addr(Self::URI)).query(&self)
69 // } else {
70 // CLIENT
71 // .post(nacos.addr(Self::URI))
72 // .query(&[("accessToken", token)])
73 // .query(&self)
74 // }
75 // .timeout(Duration::from_secs(10));
76 // let resp = res.send().await?;
77 // Ok(resp)
78 // }
79}
80
81// #[async_trait]
82pub trait Put {
83 const URI: &'static str = "/";
84
85 fn put_uri(&self) -> &'static str {
86 Self::URI
87 }
88 // async fn put(&self) -> Result<Response, Box<dyn Error + Send + Sync>>
89 // where
90 // Self: Serialize,
91 // {
92 // let nacos = NacosClient::info();
93 // let token = nacos.get_token();
94 // let res = if token == "" {
95 // CLIENT.put(nacos.addr(Self::URI)).query(&self)
96 // } else {
97 // CLIENT
98 // .put(nacos.addr(Self::URI))
99 // .query(&[("accessToken", token)])
100 // .query(&self)
101 // }
102 // .timeout(Duration::from_secs(10));
103 // let resp = res.send().await?;
104 // Ok(resp)
105 // }
106}
107
108// #[async_trait]
109pub trait Delete {
110 const URI: &'static str = "/";
111
112 fn delete_uri(&self) -> &'static str {
113 Self::URI
114 }
115 // async fn delete(&self) -> Result<Response, Box<dyn Error + Send + Sync>>
116 // where
117 // Self: Serialize,
118 // {
119 // let nacos = NacosClient::info();
120 // let token = nacos.get_token();
121 // let res = if token == "" {
122 // CLIENT.delete(nacos.addr(Self::URI)).query(&self)
123 // } else {
124 // CLIENT
125 // .delete(nacos.addr(Self::URI))
126 // .query(&[("accessToken", token)])
127 // .query(&self)
128 // }
129 // .timeout(Duration::from_secs(10));
130 // let resp = res.send().await?;
131 // Ok(resp)
132 // }
133}