Browse Source

Salvo: upgrade version to 0.21 (#7306)

Chrislearn Young 3 years ago
parent
commit
da549d3952

+ 1 - 1
frameworks/Rust/salvo/Cargo.toml

@@ -26,7 +26,7 @@ num_cpus = "1.13.0"
 once_cell = "1.5.2"
 rand = { version = "0.8.3", features = ["min_const_gen", "small_rng"] }
 random-fast-rng = "0.1.1"
-salvo = { version = "0.16", features = ["anyhow"] }
+salvo = { version = "0.21", features = ["anyhow"] }
 serde = { version = "1.0", features = ["derive"] }
 serde_derive = "1.0.125"
 serde_json = "1.0.64"

+ 1 - 1
frameworks/Rust/salvo/salvo-diesel.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.58.1
+FROM rust:1.60.0
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 

+ 1 - 1
frameworks/Rust/salvo/salvo-pg.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.58.1
+FROM rust:1.60.0
 
 RUN apt-get update -yqq && apt-get install -yqq cmake g++
 

+ 1 - 1
frameworks/Rust/salvo/salvo.dockerfile

@@ -1,4 +1,4 @@
-FROM rust:1.58.1
+FROM rust:1.60.0
 
 # Disable simd at jsonescape
 ENV CARGO_CFG_JSONESCAPE_DISABLE_AUTO_SIMD=

+ 4 - 3
frameworks/Rust/salvo/src/main.rs

@@ -23,15 +23,16 @@ pub struct Message {
 #[fn_handler]
 async fn json(res: &mut Response) {
     res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-    res.render_json(&Message {
+    res.render(Json(Message {
         message: "Hello, World!",
-    });
+    }));
 }
 
 #[fn_handler]
 async fn plaintext(res: &mut Response) {
     res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-    res.render_binary(HeaderValue::from_static("text/plain"), HELLO_WORLD);
+    res.headers_mut().insert(header::CONTENT_TYPE, HeaderValue::from_static("text/plain"));
+    res.write_body(HELLO_WORLD);
 }
 
 fn main() {

+ 5 - 5
frameworks/Rust/salvo/src/main_diesel.rs

@@ -52,7 +52,7 @@ async fn world_row(res: &mut Response) -> Result<(), Error> {
     let conn = connect()?;
     let row = world::table.find(random_id).first::<World>(&conn)?;
     res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-    res.render_json(&row);
+    res.render(Json(row));
     Ok(())
 }
 
@@ -69,7 +69,7 @@ async fn queries(req: &mut Request, res: &mut Response) -> Result<(), Error> {
         worlds.push(w);
     }
     res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-    res.render_json(&worlds);
+    res.render(Json(worlds));
     Ok(())
 }
 
@@ -87,7 +87,7 @@ async fn cached_queries(req: &mut Request, res: &mut Response) -> Result<(), Err
         }
     }
     res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-    res.render_json(&worlds);
+    res.render(Json(worlds));
     Ok(())
 }
 
@@ -116,7 +116,7 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> {
     })?;
 
     res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-    res.render_json(&worlds);
+    res.render(Json(worlds));
     Ok(())
 }
 
@@ -134,7 +134,7 @@ async fn fortunes(res: &mut Response) -> Result<(), Error> {
     write!(&mut body, "{}", FortunesTemplate { items }).unwrap();
 
     res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-    res.render_html_text(&body);
+    res.render(Text::Html(body));
     Ok(())
 }
 

+ 5 - 6
frameworks/Rust/salvo/src/main_pg.rs

@@ -194,7 +194,7 @@ impl Handler for WorldHandler {
     async fn handle(&self, _req: &mut Request, _depot: &mut Depot, res: &mut Response, _ctrl: &mut FlowCtrl) {
         res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
         let world = self.conn.get_world().await.unwrap();
-        res.render_json(&world);
+        res.render(Json(world));
     }
 }
 struct WorldsHandler {
@@ -216,7 +216,7 @@ impl Handler for WorldsHandler {
         let count = cmp::min(500, cmp::max(1, count));
         res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
         let worlds = self.conn.get_worlds(count).await.unwrap();
-        res.render_json(&worlds);
+        res.render(Json(worlds));
     }
 }
 struct UpdatesHandler {
@@ -238,7 +238,7 @@ impl Handler for UpdatesHandler {
         let count = cmp::min(500, cmp::max(1, count));
         res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
         let worlds = self.conn.update(count).await.unwrap();
-        res.render_json(&worlds);
+        res.render(Json(worlds));
     }
 }
 struct FortunesHandler {
@@ -258,9 +258,8 @@ impl Handler for FortunesHandler {
     async fn handle(&self, _req: &mut Request, _depot: &mut Depot, res: &mut Response, _ctrl: &mut FlowCtrl) {
         let mut body = String::new();
         write!(&mut body, "{}", self.conn.tell_fortune().await.unwrap()).unwrap();
-
         res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-        res.render_html_text(&body);
+        res.render(Text::Html(body));
     }
 }
 
@@ -278,7 +277,7 @@ async fn cached_queries(req: &mut Request, res: &mut Response) -> Result<(), Err
         }
     }
     res.headers_mut().insert(header::SERVER, HeaderValue::from_static("S"));
-    res.render_json(&worlds);
+    res.render(Json(worlds));
     Ok(())
 }