Skip to main content

nacos_api/model/
service_dto.rs

1use crate::model::Dto;
2use std::collections::HashMap;
3use nacos_api_macro::Dto;
4
5#[derive(Default, Dto)]
6/// 注册实例的可选项
7pub struct RegisterInstanceOption {
8    /// 命名空间ID
9    namespace_id: Option<String>,
10    /// 权重
11    weight: Option<f64>,
12    /// 是否上线
13    enabled: Option<bool>,
14    /// 是否健康
15    healthy: Option<bool>,
16    /// 扩展信息
17    metadata: Option<String>,
18    /// 集群名
19    cluster_name: Option<String>,
20}
21
22impl RegisterInstanceOption {
23    pub fn set_namespace_id(&mut self, namespace_id: Option<String>) {
24        self.namespace_id = namespace_id;
25    }
26    pub fn set_weight(&mut self, weight: Option<f64>) {
27        self.weight = weight;
28    }
29    pub fn set_enabled(&mut self, enabled: Option<bool>) {
30        self.enabled = enabled;
31    }
32    pub fn set_healthy(&mut self, healthy: Option<bool>) {
33        self.healthy = healthy;
34    }
35    pub fn set_metadata(&mut self, metadata: Option<String>) {
36        self.metadata = metadata;
37    }
38    pub fn set_cluster_name(&mut self, cluster_name: Option<String>) {
39        self.cluster_name = cluster_name;
40    }
41    pub fn namespace_id(&self) -> &Option<String> {
42        &self.namespace_id
43    }
44    pub fn weight(&self) -> Option<f64> {
45        self.weight
46    }
47    pub fn enabled(&self) -> Option<bool> {
48        self.enabled
49    }
50    pub fn healthy(&self) -> Option<bool> {
51        self.healthy
52    }
53    pub fn metadata(&self) -> &Option<String> {
54        &self.metadata
55    }
56    pub fn cluster_name(&self) -> &Option<String> {
57        &self.cluster_name
58    }
59}
60
61impl RegisterInstanceOption {
62    pub fn new(namespace_id: Option<String>, weight: Option<f64>, enabled: Option<bool>, healthy: Option<bool>, metadata: Option<String>, cluster_name: Option<String>) -> Self {
63        RegisterInstanceOption { namespace_id, weight, enabled, healthy, metadata, cluster_name }
64    }
65}
66
67/// 注销实例可选项
68#[derive(Default, Dto)]
69pub struct RemoveInstanceOption {
70    /// 集群名称
71    cluster_name: Option<String>,
72    /// 命名空间ID
73    namespace_id: Option<String>,
74}
75
76impl RemoveInstanceOption {
77    pub fn set_cluster_name(&mut self, cluster_name: Option<String>) {
78        self.cluster_name = cluster_name;
79    }
80    pub fn set_namespace_id(&mut self, namespace_id: Option<String>) {
81        self.namespace_id = namespace_id;
82    }
83    pub fn cluster_name(&self) -> &Option<String> {
84        &self.cluster_name
85    }
86    pub fn namespace_id(&self) -> &Option<String> {
87        &self.namespace_id
88    }
89}
90
91#[derive(Default, Dto)]
92/// 修改实例可选项
93pub struct UpdateInstanceOption {
94    /// 集群名称
95    cluster_name: Option<String>,
96    /// 命名空间ID
97    namespace_id: Option<String>,
98    /// 权重
99    weight: Option<f64>,
100    /// 扩展信息 JSON
101    metadata: Option<String>,
102    /// 是否打开流量
103    enabled: Option<bool>,
104}
105
106impl UpdateInstanceOption {
107    pub fn set_cluster_name(&mut self, cluster_name: Option<String>) {
108        self.cluster_name = cluster_name;
109    }
110    pub fn set_namespace_id(&mut self, namespace_id: Option<String>) {
111        self.namespace_id = namespace_id;
112    }
113    pub fn set_weight(&mut self, weight: Option<f64>) {
114        self.weight = weight;
115    }
116    pub fn set_metadata(&mut self, metadata: Option<String>) {
117        self.metadata = metadata;
118    }
119    pub fn set_enabled(&mut self, enabled: Option<bool>) {
120        self.enabled = enabled;
121    }
122    pub fn cluster_name(&self) -> &Option<String> {
123        &self.cluster_name
124    }
125    pub fn namespace_id(&self) -> &Option<String> {
126        &self.namespace_id
127    }
128    pub fn weight(&self) -> Option<f64> {
129        self.weight
130    }
131    pub fn metadata(&self) -> &Option<String> {
132        &self.metadata
133    }
134    pub fn enabled(&self) -> Option<bool> {
135        self.enabled
136    }
137}
138
139#[derive(Default, Dto)]
140/// 获取实例选项
141pub struct GetInstanceOption {
142    /// 命名空间ID
143    namespace_id: Option<String>,
144    /// 集群名称 多个用 , 分割
145    clusters: Option<String>,
146    /// 是否只返回健康实例
147    healthy_only: Option<bool>,
148}
149
150impl GetInstanceOption {
151    pub fn set_namespace_id(&mut self, namespace_id: Option<String>) {
152        self.namespace_id = namespace_id;
153    }
154    pub fn set_clusters(&mut self, clusters: Option<String>) {
155        self.clusters = clusters;
156    }
157    pub fn set_healthy_only(&mut self, healthy_only: Option<bool>) {
158        self.healthy_only = healthy_only;
159    }
160    pub fn namespace_id(&self) -> &Option<String> {
161        &self.namespace_id
162    }
163    pub fn clusters(&self) -> &Option<String> {
164        &self.clusters
165    }
166    pub fn healthy_only(&self) -> Option<bool> {
167        self.healthy_only
168    }
169}
170
171#[derive(Debug, Default, Dto)]
172pub struct PostServiceOption {
173    group_name: Option<String>,
174    namespace_id: Option<String>,
175    protect_threshold: Option<f64>,
176    metadata: Option<String>,
177    selector: Option<String>,
178}
179
180impl PostServiceOption {
181    pub fn set_group_name(&mut self, group_name: Option<String>) {
182        self.group_name = group_name;
183    }
184    pub fn set_namespace_id(&mut self, namespace_id: Option<String>) {
185        self.namespace_id = namespace_id;
186    }
187    pub fn set_protect_threshold(&mut self, protect_threshold: Option<f64>) {
188        self.protect_threshold = protect_threshold;
189    }
190    pub fn set_metadata(&mut self, metadata: Option<String>) {
191        self.metadata = metadata;
192    }
193    pub fn set_selector(&mut self, selector: Option<String>) {
194        self.selector = selector;
195    }
196    pub fn group_name(&self) -> &Option<String> {
197        &self.group_name
198    }
199    pub fn namespace_id(&self) -> &Option<String> {
200        &self.namespace_id
201    }
202    pub fn protect_threshold(&self) -> Option<f64> {
203        self.protect_threshold
204    }
205    pub fn metadata(&self) -> &Option<String> {
206        &self.metadata
207    }
208    pub fn selector(&self) -> &Option<String> {
209        &self.selector
210    }
211}
212
213#[derive(Debug, Default, Dto)]
214pub struct DeleteServiceOption {
215    group_name: Option<String>,
216    namespace_id: Option<String>,
217}
218
219impl DeleteServiceOption {
220    pub fn set_group_name(&mut self, group_name: Option<String>) {
221        self.group_name = group_name;
222    }
223    pub fn set_namespace_id(&mut self, namespace_id: Option<String>) {
224        self.namespace_id = namespace_id;
225    }
226    pub fn group_name(&self) -> &Option<String> {
227        &self.group_name
228    }
229    pub fn namespace_id(&self) -> &Option<String> {
230        &self.namespace_id
231    }
232}
233
234#[derive(Debug, Default, Dto)]
235pub struct PutServiceOption {
236    group_name: Option<String>,
237    namespace_id: Option<String>,
238    protect_threshold: Option<f64>,
239    metadata: Option<String>,
240    selector: Option<String>,
241}
242
243impl PutServiceOption {
244    pub fn set_group_name(&mut self, group_name: Option<String>) {
245        self.group_name = group_name;
246    }
247    pub fn set_namespace_id(&mut self, namespace_id: Option<String>) {
248        self.namespace_id = namespace_id;
249    }
250    pub fn set_protect_threshold(&mut self, protect_threshold: Option<f64>) {
251        self.protect_threshold = protect_threshold;
252    }
253    pub fn set_metadata(&mut self, metadata: Option<String>) {
254        self.metadata = metadata;
255    }
256    pub fn set_selector(&mut self, selector: Option<String>) {
257        self.selector = selector;
258    }
259    pub fn group_name(&self) -> &Option<String> {
260        &self.group_name
261    }
262    pub fn namespace_id(&self) -> &Option<String> {
263        &self.namespace_id
264    }
265    pub fn protect_threshold(&self) -> Option<f64> {
266        self.protect_threshold
267    }
268    pub fn metadata(&self) -> &Option<String> {
269        &self.metadata
270    }
271    pub fn selector(&self) -> &Option<String> {
272        &self.selector
273    }
274}
275
276#[derive(Debug, Default, Dto)]
277pub struct GetServiceOption {
278    group_name: Option<String>,
279    namespace_id: Option<String>,
280}
281
282impl GetServiceOption {
283    pub fn set_group_name(&mut self, group_name: Option<String>) {
284        self.group_name = group_name;
285    }
286    pub fn set_namespace_id(&mut self, namespace_id: Option<String>) {
287        self.namespace_id = namespace_id;
288    }
289    pub fn group_name(&self) -> &Option<String> {
290        &self.group_name
291    }
292    pub fn namespace_id(&self) -> &Option<String> {
293        &self.namespace_id
294    }
295}
296
297#[derive(Debug, Default, Dto)]
298pub struct PostConfigsOption {
299
300}