Skip to content

Commit d8d779e

Browse files
authored
update ohkami to v0.17 (#8942)
* update ohkami v0.16 -> v0.17 & refactor some * Fix: dockerfile
1 parent eeadf09 commit d8d779e

File tree

9 files changed

+156
-107
lines changed

9 files changed

+156
-107
lines changed

frameworks/Rust/ohkami/Cargo.lock

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/Rust/ohkami/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "ohkami_framework_benchmarks"
3-
version = "0.15.0"
3+
version = "0.17.1"
44
edition = "2021"
55
authors = ["kanarus <[email protected]>"]
66

77
[dependencies]
8-
ohkami = { version = "=0.16.0", features = ["rt_tokio"] }
8+
ohkami = { version = "=0.17.1", features = ["rt_tokio"] }
99
tokio = { version = "1.37.0" , features = ["full"] }
1010
rand = { version = "0.8.5" , features = ["small_rng"] }
1111
sqlx = { version = "0.7.4" , features = ["postgres", "macros", "runtime-tokio-native-tls"] }
1212
yarte = { version = "0.15.7" }
13-
futures-util = { version = "0.3.30" }
13+
futures-util = { version = "0.3.30" }

frameworks/Rust/ohkami/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> Build web app in intuitive and declarative code
66
> - *macro-less and type-safe* APIs for intuitive and declarative code
7-
> - *multi runtime* support:`tokio`, `async-std`
7+
> - *multi runtime* support:`tokio`, `async-std`, `worker` (Cloudflare Workers)
88
99
- [User Guide](https://docs.rs/ohkami/latest/ohkami/)
1010
- [API Documentation](https://docs.rs/ohkami/latest/ohkami/)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
FROM rust:1.76-slim-buster
1+
FROM rust:1.77-slim-buster
22
WORKDIR /ohkami_framework_benchmarks
33

44
ENV DATABASE_URL=postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world
55
ENV MAX_CONNECTIONS=56
66
ENV MIN_CONNECTIONS=56
77

88
COPY ./src ./src
9-
COPY ./templates ./templates
109
COPY ./Cargo.toml ./Cargo.toml
1110
COPY ./Cargo.lock ./Cargo.lock
1211

@@ -16,4 +15,4 @@ RUN apt update && apt install -y --no-install-recommends \
1615

1716
RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
1817
EXPOSE 8000
19-
CMD ./target/release/ohkami_framework_benchmarks
18+
CMD ./target/release/ohkami_framework_benchmarks

frameworks/Rust/ohkami/src/fangs.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
use ohkami::prelude::*;
2+
use crate::Postgres;
3+
4+
5+
#[derive(Clone)]
6+
pub struct SetServer;
7+
impl FangAction for SetServer {
8+
#[inline(always)]
9+
async fn back<'a>(&'a self, res: &'a mut ohkami::Response) {
10+
res.headers.set().Server("ohkami");
11+
}
12+
}
13+
14+
#[derive(Clone)]
15+
pub struct UsePostgres(
16+
Postgres
17+
);
18+
impl UsePostgres {
19+
pub async fn init() -> Self {
20+
macro_rules! load_env {
21+
($($name:ident as $t:ty)*) => {$(
22+
#[allow(non_snake_case)]
23+
let $name = ::std::env::var(stringify!($name))
24+
.expect(concat!(
25+
"Failed to load environment variable ",
26+
"`", stringify!($name), "`"
27+
))
28+
.parse::<$t>()
29+
.unwrap();
30+
)*};
31+
} load_env! {
32+
MAX_CONNECTIONS as u32
33+
MIN_CONNECTIONS as u32
34+
DATABASE_URL as String
35+
}
36+
37+
let pool = sqlx::postgres::PgPoolOptions::new()
38+
.max_connections(MAX_CONNECTIONS)
39+
.min_connections(MIN_CONNECTIONS)
40+
.connect(&DATABASE_URL).await
41+
.unwrap();
42+
43+
Self(pool.into())
44+
}
45+
}
46+
impl FangAction for UsePostgres {
47+
#[inline(always)]
48+
async fn fore<'a>(&'a self, req: &'a mut Request) -> Result<(), Response> {
49+
Ok(req.memorize(self.0.clone()))
50+
}
51+
}
52+
53+
54+
/*
55+
impl Postgres {
56+
pub async fn init() -> impl FangAction {
57+
#[derive(Clone)]
58+
pub struct UsePostgres(Postgres);
59+
60+
impl FangAction for UsePostgres {
61+
#[inline(always)]
62+
async fn fore<'a>(&'a self, req: &'a mut Request) -> Result<(), Response> {
63+
req.memorize(self.0.clone());
64+
Ok(())
65+
}
66+
}
67+
68+
macro_rules! load_env {
69+
($($name:ident as $t:ty)*) => {
70+
$(
71+
#[allow(non_snake_case)]
72+
let $name = ::std::env::var(stringify!($name))
73+
.expect(concat!(
74+
"Failed to load environment variable ",
75+
"`", stringify!($name), "`"
76+
))
77+
.parse::<$t>()
78+
.unwrap();
79+
)*
80+
};
81+
} load_env! {
82+
MAX_CONNECTIONS as u32
83+
MIN_CONNECTIONS as u32
84+
DATABASE_URL as String
85+
}
86+
87+
UsePostgres(Self(
88+
sqlx::postgres::PgPoolOptions::new()
89+
.max_connections(MAX_CONNECTIONS)
90+
.min_connections(MIN_CONNECTIONS)
91+
.connect(&DATABASE_URL).await
92+
.unwrap()
93+
))
94+
}
95+
}
96+
*/

0 commit comments

Comments
 (0)