1use std::collections::HashMap;
2use std::time::Duration;
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug, Default)]
8pub struct QueryOptions {
9 pub datacenter: Option<String>,
11 pub allow_stale: bool,
13 pub require_consistent: bool,
15 pub use_cache: bool,
17 pub max_age: Option<Duration>,
19 pub stale_if_error: Option<Duration>,
21 pub wait_index: u64,
23 pub wait_time: Option<Duration>,
25 pub token: Option<String>,
27 pub namespace: Option<String>,
29 pub partition: Option<String>,
31 pub near: Option<String>,
33 pub node_meta: HashMap<String, String>,
35 pub filter: Option<String>,
37}
38
39impl QueryOptions {
40 pub fn new() -> Self {
41 Self::default()
42 }
43
44 pub fn with_token(mut self, token: &str) -> Self {
45 self.token = Some(token.to_string());
46 self
47 }
48
49 pub fn with_datacenter(mut self, dc: &str) -> Self {
50 self.datacenter = Some(dc.to_string());
51 self
52 }
53
54 pub fn with_namespace(mut self, ns: &str) -> Self {
55 self.namespace = Some(ns.to_string());
56 self
57 }
58
59 pub fn with_wait(mut self, index: u64, wait_time: Duration) -> Self {
60 self.wait_index = index;
61 self.wait_time = Some(wait_time);
62 self
63 }
64
65 pub fn with_stale(mut self) -> Self {
66 self.allow_stale = true;
67 self
68 }
69
70 pub fn with_consistent(mut self) -> Self {
71 self.require_consistent = true;
72 self
73 }
74}
75
76#[derive(Clone, Debug, Default)]
78pub struct WriteOptions {
79 pub datacenter: Option<String>,
81 pub token: Option<String>,
83 pub namespace: Option<String>,
85 pub partition: Option<String>,
87}
88
89impl WriteOptions {
90 pub fn new() -> Self {
91 Self::default()
92 }
93
94 pub fn with_token(mut self, token: &str) -> Self {
95 self.token = Some(token.to_string());
96 self
97 }
98
99 pub fn with_datacenter(mut self, dc: &str) -> Self {
100 self.datacenter = Some(dc.to_string());
101 self
102 }
103
104 pub fn with_namespace(mut self, ns: &str) -> Self {
105 self.namespace = Some(ns.to_string());
106 self
107 }
108}
109
110#[derive(Clone, Debug, Default)]
112pub struct QueryMeta {
113 pub last_index: u64,
115 pub last_contact: Duration,
117 pub known_leader: bool,
119 pub request_time: Duration,
121 pub address_translation_enabled: bool,
123 pub cache_hit: bool,
125 pub cache_age: Option<Duration>,
127}
128
129#[derive(Clone, Debug, Default)]
131pub struct WriteMeta {
132 pub request_time: Duration,
134}
135
136#[derive(Clone, Debug, Serialize, Deserialize)]
138#[serde(rename_all = "PascalCase")]
139pub struct Node {
140 #[serde(rename = "ID")]
142 pub id: String,
143 pub node: String,
145 pub address: String,
147 pub datacenter: String,
149 #[serde(default)]
151 pub tagged_addresses: HashMap<String, String>,
152 #[serde(default)]
154 pub meta: HashMap<String, String>,
155 pub create_index: u64,
157 pub modify_index: u64,
159}
160
161#[derive(Clone, Debug, Serialize, Deserialize)]
163#[serde(rename_all = "PascalCase")]
164pub struct AgentService {
165 #[serde(rename = "ID")]
167 pub id: String,
168 pub service: String,
170 #[serde(default)]
172 pub tags: Vec<String>,
173 pub port: u16,
175 #[serde(default)]
177 pub address: String,
178 #[serde(default)]
180 pub enable_tag_override: bool,
181 #[serde(default)]
183 pub meta: HashMap<String, String>,
184 #[serde(default)]
186 pub weights: Option<ServiceWeights>,
187}
188
189#[derive(Clone, Debug, Serialize, Deserialize)]
191#[serde(rename_all = "PascalCase")]
192pub struct ServiceWeights {
193 pub passing: i32,
195 pub warning: i32,
197}
198
199impl Default for ServiceWeights {
200 fn default() -> Self {
201 Self {
202 passing: 1,
203 warning: 1,
204 }
205 }
206}
207
208#[derive(Clone, Debug, Serialize, Deserialize)]
210#[serde(rename_all = "PascalCase")]
211pub struct CatalogService {
212 #[serde(rename = "ID")]
214 pub id: String,
215 pub node: String,
217 pub address: String,
219 pub datacenter: String,
221 #[serde(default)]
223 pub tagged_addresses: HashMap<String, String>,
224 #[serde(default)]
226 pub node_meta: HashMap<String, String>,
227 #[serde(rename = "ServiceID")]
229 pub service_id: String,
230 pub service_name: String,
232 #[serde(default)]
234 pub service_tags: Vec<String>,
235 #[serde(default)]
237 pub service_address: String,
238 pub service_port: u16,
240 #[serde(default)]
242 pub service_meta: HashMap<String, String>,
243 #[serde(default)]
245 pub service_weights: Option<ServiceWeights>,
246 pub create_index: u64,
248 pub modify_index: u64,
250}
251
252#[derive(Clone, Debug, Serialize, Deserialize)]
254#[serde(rename_all = "PascalCase")]
255pub struct HealthCheck {
256 pub node: String,
258 #[serde(rename = "CheckID")]
260 pub check_id: String,
261 pub name: String,
263 pub status: String,
265 #[serde(default)]
267 pub notes: String,
268 #[serde(default)]
270 pub output: String,
271 #[serde(rename = "ServiceID")]
273 #[serde(default)]
274 pub service_id: String,
275 #[serde(default)]
277 pub service_name: String,
278 #[serde(default)]
280 pub service_tags: Vec<String>,
281 #[serde(rename = "Type")]
283 #[serde(default)]
284 pub check_type: String,
285 pub create_index: u64,
287 pub modify_index: u64,
289}
290
291#[derive(Clone, Debug, Serialize, Deserialize)]
293#[serde(rename_all = "PascalCase")]
294pub struct ServiceEntry {
295 pub node: Node,
297 pub service: AgentService,
299 pub checks: Vec<HealthCheck>,
301}