Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 6552000

Browse files
committed
fix formatting
1 parent fe1efb0 commit 6552000

File tree

8 files changed

+303
-165
lines changed

8 files changed

+303
-165
lines changed

src/app/client.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::collections::HashMap;
2-
use std::path::{Path, PathBuf};
3-
use std::sync::atomic::{AtomicU64, Ordering};
41
use anyhow::{bail, Context, Result};
52
use serde::{Deserialize, Serialize};
63
use serde_json::{self as encoder, Value};
4+
use std::collections::HashMap;
5+
use std::path::{Path, PathBuf};
6+
use std::sync::atomic::{AtomicU64, Ordering};
77
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufStream};
88
use tokio::net::UnixStream;
99

@@ -62,19 +62,20 @@ impl Client {
6262
async fn jsonrpc_request(&self, method: &str, params: Option<Value>) -> Result<Value> {
6363
// First try JSON-RPC
6464
let result = self.try_jsonrpc(method, params.clone()).await;
65-
65+
6666
// If JSON-RPC fails, try legacy protocol
6767
if let Err(e) = &result {
68-
if e.to_string().contains("Invalid JSON-RPC response") ||
69-
e.to_string().contains("Failed to parse") {
68+
if e.to_string().contains("Invalid JSON-RPC response")
69+
|| e.to_string().contains("Failed to parse")
70+
{
7071
debug!("JSON-RPC failed, trying legacy protocol: {}", e);
7172
return self.try_legacy_protocol(method, params).await;
7273
}
7374
}
74-
75+
7576
result
7677
}
77-
78+
7879
// Try using JSON-RPC protocol
7980
async fn try_jsonrpc(&self, method: &str, params: Option<Value>) -> Result<Value> {
8081
// Get a unique ID for this request
@@ -146,7 +147,7 @@ impl Client {
146147
} else {
147148
bail!("Missing parameters");
148149
}
149-
},
150+
}
150151
"service.start" => {
151152
if let Some(params) = params {
152153
if let Some(name) = params.get("name").and_then(|v| v.as_str()) {
@@ -157,7 +158,7 @@ impl Client {
157158
} else {
158159
bail!("Missing parameters");
159160
}
160-
},
161+
}
161162
"service.stop" => {
162163
if let Some(params) = params {
163164
if let Some(name) = params.get("name").and_then(|v| v.as_str()) {
@@ -168,7 +169,7 @@ impl Client {
168169
} else {
169170
bail!("Missing parameters");
170171
}
171-
},
172+
}
172173
"service.forget" => {
173174
if let Some(params) = params {
174175
if let Some(name) = params.get("name").and_then(|v| v.as_str()) {
@@ -179,7 +180,7 @@ impl Client {
179180
} else {
180181
bail!("Missing parameters");
181182
}
182-
},
183+
}
183184
"service.monitor" => {
184185
if let Some(params) = params {
185186
if let Some(name) = params.get("name").and_then(|v| v.as_str()) {
@@ -190,7 +191,7 @@ impl Client {
190191
} else {
191192
bail!("Missing parameters");
192193
}
193-
},
194+
}
194195
"service.kill" => {
195196
if let Some(params) = params {
196197
if let Some(name) = params.get("name").and_then(|v| v.as_str()) {
@@ -205,23 +206,23 @@ impl Client {
205206
} else {
206207
bail!("Missing parameters");
207208
}
208-
},
209+
}
209210
"service.create" => {
210211
// The legacy protocol doesn't directly support service creation
211212
bail!("Service creation not supported in legacy protocol");
212-
},
213+
}
213214
"service.delete" => {
214215
// The legacy protocol doesn't directly support service deletion
215216
bail!("Service deletion not supported in legacy protocol");
216-
},
217+
}
217218
"service.get" => {
218219
// The legacy protocol doesn't directly support getting service config
219220
bail!("Getting service configuration not supported in legacy protocol");
220-
},
221+
}
221222
"rpc.discover" => {
222223
// This is a JSON-RPC specific method with no legacy equivalent
223224
bail!("RPC discovery not supported in legacy protocol");
224-
},
225+
}
225226
"service.restart" => {
226227
if let Some(params) = params {
227228
if let Some(name) = params.get("name").and_then(|v| v.as_str()) {
@@ -232,7 +233,7 @@ impl Client {
232233
} else {
233234
bail!("Missing parameters");
234235
}
235-
},
236+
}
236237
"log" => {
237238
if let Some(params) = params {
238239
if let Some(filter) = params.get("filter").and_then(|v| v.as_str()) {
@@ -251,7 +252,7 @@ impl Client {
251252
} else {
252253
"log".to_string()
253254
}
254-
},
255+
}
255256
_ => bail!("Unsupported method for legacy protocol: {}", method),
256257
};
257258

@@ -450,4 +451,4 @@ impl Client {
450451

451452
self.jsonrpc_request("service.get", Some(params)).await
452453
}
453-
}
454+
}

src/app/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
pub mod server;
21
pub mod client;
2+
pub mod server;
33

4-
use crate::zinit;
5-
use self::server::Api;
64
use self::client::Client;
5+
use self::server::Api;
6+
use crate::zinit;
77
use anyhow::{Context, Result};
88
use serde_yaml as encoder;
99
use std::path::{Path, PathBuf};
@@ -173,4 +173,4 @@ pub async fn logs(socket: &str, filter: Option<&str>, follow: bool) -> Result<()
173173
client.status(filter).await?;
174174
}
175175
client.logs(tokio::io::stdout(), filter, follow).await
176-
}
176+
}

src/app/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ impl Api {
770770
name
771771
)))
772772
}
773-
773+
774774
async fn delete_service<S: AsRef<str>>(name: S, zinit: ZInit) -> Result<Value> {
775775
use std::fs;
776776

@@ -797,7 +797,7 @@ impl Api {
797797
name
798798
)))
799799
}
800-
800+
801801
async fn get_service<S: AsRef<str>>(name: S, zinit: ZInit) -> Result<Value> {
802802
use std::fs;
803803

0 commit comments

Comments
 (0)