Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0 #73

Merged
merged 62 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e444345
Merge pull request #57 from hubertshelley/features/2.0/refactor_service
hubertshelley Aug 6, 2024
6ba8997
refactor: exception_handler重构
hubertshelley Aug 7, 2024
27dc0da
refactor: next重构
hubertshelley Aug 7, 2024
c353332
refactor: next重构, 新增request_time_logger中间件
hubertshelley Aug 7, 2024
8e5cdda
Merge pull request #58 from hubertshelley/features/2.0/refactor_excep…
hubertshelley Aug 7, 2024
dbeef2d
refactor: exception_handler重构
hubertshelley Aug 7, 2024
3c68909
exception_handler 错误修复
hubertshelley Aug 7, 2024
e61b24c
Merge branch 'refs/heads/2.0.0' into features/2.0/refactor_next
hubertshelley Aug 7, 2024
ba4be12
Merge pull request #59 from hubertshelley/features/2.0/refactor_next
hubertshelley Aug 7, 2024
1b559f6
refactor: grpc重构
hubertshelley Aug 7, 2024
fdb74f4
Merge pull request #60 from hubertshelley/features/2.0/refactor_grpc
hubertshelley Aug 7, 2024
ff39f04
request添加form_parse、json_field方法
hubertshelley Aug 12, 2024
92831ff
Merge pull request #62 from hubertshelley/features/2.0/request
hubertshelley Aug 12, 2024
0c0e680
feat[plugin]: 添加plugin示例
hubertshelley Sep 5, 2024
0dcbd52
feat: cookie scheduler重构
hubertshelley Sep 6, 2024
a3ab9dd
异常处理
hubertshelley Sep 6, 2024
2b3202a
Merge pull request #64 from hubertshelley/features/2.0/scheduler
hubertshelley Sep 6, 2024
6c17bc8
Merge pull request #65 from hubertshelley/features/2.0/plugin-support
hubertshelley Sep 6, 2024
a608f37
feat: 调整prelude
hubertshelley Sep 14, 2024
e8f42f1
feat: 调整prelude
hubertshelley Sep 14, 2024
d4904dd
feat: 调整prelude
hubertshelley Sep 14, 2024
be5117e
feat: 添加超时中间件及相关示例代码
hubertshelley Sep 14, 2024
bcbac19
feat: websocket调整
hubertshelley Sep 14, 2024
4a98ade
chore: deps update
hubertshelley Oct 11, 2024
73bd837
chore: session优化调整
hubertshelley Oct 12, 2024
ddb6672
合并拉取请求 #67
hubertshelley Oct 14, 2024
2df1cb5
fix: cors 异常修复
hubertshelley Oct 14, 2024
d099dd5
Merge pull request #68 from hubertshelley/features/2.0/cors_fix
hubertshelley Oct 14, 2024
ec77942
feat: support vec in query by serde_html_form
hubertshelley Nov 8, 2024
a65f2c8
Merge pull request #71 from hubertshelley/features/2.0/query_vec_support
hubertshelley Nov 8, 2024
c52e0b0
feat: sse微调
hubertshelley Nov 8, 2024
c17ba3d
Merge pull request #72 from hubertshelley/features/2.0/sse_refactor
hubertshelley Nov 12, 2024
fdd4d2c
feat: 调整版本号
hubertshelley Nov 21, 2024
dac382f
feat: moute match edit
hubertshelley Nov 26, 2024
b334782
chore: grpc file name edit
hubertshelley Nov 29, 2024
7d1ded7
Merge remote-tracking branch 'origin/2.0.0' into 2.0.0
hubertshelley Nov 29, 2024
f727664
refactor: next重构
hubertshelley Aug 7, 2024
fd991e0
refactor: next重构, 新增request_time_logger中间件
hubertshelley Aug 7, 2024
25a7097
refactor: exception_handler重构
hubertshelley Aug 7, 2024
4bcbc02
exception_handler 错误修复
hubertshelley Aug 7, 2024
4c077c0
refactor: exception_handler重构
hubertshelley Aug 7, 2024
e79d90b
refactor: grpc重构
hubertshelley Aug 7, 2024
85b3d12
request添加form_parse、json_field方法
hubertshelley Aug 12, 2024
cb161f1
feat: cookie scheduler重构
hubertshelley Sep 6, 2024
8c41d1f
异常处理
hubertshelley Sep 6, 2024
f567169
feat[plugin]: 添加plugin示例
hubertshelley Sep 5, 2024
eb42843
feat: 调整prelude
hubertshelley Sep 14, 2024
6690527
feat: 调整prelude
hubertshelley Sep 14, 2024
577286d
feat: 调整prelude
hubertshelley Sep 14, 2024
fcdd78c
feat: 添加超时中间件及相关示例代码
hubertshelley Sep 14, 2024
4f022a2
feat: websocket调整
hubertshelley Sep 14, 2024
3c67c3a
chore: deps update
hubertshelley Oct 11, 2024
c2ce99d
chore: session优化调整
hubertshelley Oct 12, 2024
1e050c3
合并拉取请求 #67
hubertshelley Oct 14, 2024
05bedd3
fix: cors 异常修复
hubertshelley Oct 14, 2024
f37163d
chore: grpc file name edit
hubertshelley Nov 29, 2024
ed1d4f5
feat: sse微调
hubertshelley Nov 8, 2024
4ed4938
feat: 调整版本号
hubertshelley Nov 21, 2024
c772fd6
feat: moute match edit
hubertshelley Nov 26, 2024
7acee78
合并异常处理
hubertshelley Dec 3, 2024
bad9c3f
Merge remote-tracking branch 'origin/2.0.0' into 2.0.0
hubertshelley Dec 3, 2024
a5655d5
合并异常处理
hubertshelley Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ homepage = "https://github.com/hubertshelley/silent"
license = "Apache-2.0"
readme = "./readme.md"
repository = "https://github.com/hubertshelley/silent"
version = "1.5.0"
version = "2.0.0"
11 changes: 4 additions & 7 deletions examples/exception_handler/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use serde::{Deserialize, Serialize};

use silent::middlewares::ExceptionHandler;
use silent::prelude::*;

#[derive(Deserialize, Serialize, Debug)]
Expand All @@ -10,13 +12,8 @@ struct Exception {
fn main() {
logger::fmt().with_max_level(Level::INFO).init();
let route = Route::new("")
.root_hook(ExceptionHandler::new(|res, _| async move { res }))
.get(|mut req| async move { req.params_parse::<Exception>() })
.route()
.set_exception_handler(|e, _| async move {
Exception {
code: e.status().as_u16(),
msg: e.to_string(),
}
});
.route();
Server::new().run(route);
}
2 changes: 1 addition & 1 deletion examples/form/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
serde = { version = "1.0.213", features = ["derive"] }
serde = { version = "1.0.210", features = ["derive"] }
2 changes: 1 addition & 1 deletion examples/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/client.rs"
[dependencies]
tonic = { version = "0.12.3" }
prost = "0.13"
tokio = { version = "1.41", features = ["macros", "rt-multi-thread"] }
tokio = { version = "1.40", features = ["macros", "rt-multi-thread"] }
silent = { path = "../../silent", features = ["grpc"] }
async-trait = "0.1.83"

Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
tonic_build::configure()
.compile(&["proto/helloworld.proto"], &["/proto"])
.compile_protos(&["proto/hello_world.proto"], &["/proto"])
.unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_package = "io.grpc.examples.hello_world";
option java_outer_classname = "HelloWorldProto";

package helloworld;
package hello_world;

// The greeting service definition.
service Greeter {
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use hello_world::greeter_client::GreeterClient;
use hello_world::HelloRequest;

pub mod hello_world {
tonic::include_proto!("helloworld");
tonic::include_proto!("hello_world");
}
#[allow(dead_code)]
#[tokio::main]
Expand Down
16 changes: 9 additions & 7 deletions examples/grpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use tonic::{Request, Response, Status};

use hello_world::greeter_server::{Greeter, GreeterServer};
use hello_world::{HelloReply, HelloRequest};
use silent::prelude::{logger, HandlerAppend, Level, Route, RouteService, Server};
use silent::prelude::{info, logger, HandlerAppend, Level, Route, Server};
use silent::GrpcRegister;

mod client;

pub mod hello_world {
tonic::include_proto!("helloworld"); // The string specified here must match the proto package name
tonic::include_proto!("hello_world"); // The string specified here must match the proto package name
}

#[derive(Debug, Default)]
Expand All @@ -21,7 +22,7 @@ impl Greeter for MyGreeter {
request: Request<HelloRequest>, // Accept request of type HelloRequest
) -> Result<Response<HelloReply>, Status> {
// Return an instance of type HelloReply
println!("Got a request: {:?}", request);
info!("Got a request: {:?}", request);

let reply = HelloReply {
message: format!("Hello {}!", request.into_inner().name), // We must use .into_inner() as the fields of gRPC requests and responses are private
Expand All @@ -40,12 +41,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// // Wrap all services in the middleware stack
// .add_service(greeter_server)
// .into_router();
let route = Route::new("").get(|_req| async { Ok("hello world") });
let root = route.route().with_grpc(greeter_server.into());
println!("route: \n{:?}", root);
let route = Route::new("")
.get(|_req| async { Ok("hello world") })
.append(greeter_server.service());
info!("route: \n{:?}", route);
Server::new()
.bind("0.0.0.0:50051".parse().unwrap())
.serve(root)
.serve(route)
.await;
Ok(())
}
4 changes: 2 additions & 2 deletions examples/grpc_h2c/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

tonic_build::configure()
.file_descriptor_set_path(out_dir.join("helloworld_descriptor.bin"))
.compile(&["proto/helloworld.proto"], &["/proto"])
.file_descriptor_set_path(out_dir.join("hello_world_descriptor.bin"))
.compile_protos(&["proto/hello_world.proto"], &["/proto"])
.unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_package = "io.grpc.examples.hello_world";
option java_outer_classname = "HelloWorldProto";

package helloworld;
package hello_world;

// The greeting service definition.
service Greeter {
Expand All @@ -34,4 +34,4 @@ message HelloRequest {
// The response message containing the greetings
message HelloReply {
string message = 1;
}
}
2 changes: 1 addition & 1 deletion examples/grpc_h2c/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;

pub mod hello_world {
tonic::include_proto!("helloworld");
tonic::include_proto!("hello_world");
}

#[tokio::main]
Expand Down
13 changes: 7 additions & 6 deletions examples/grpc_h2c/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use tonic::{Request, Response, Status};

use hello_world::greeter_server::{Greeter, GreeterServer};
use hello_world::{HelloReply, HelloRequest};
use silent::prelude::{logger, HandlerAppend, Level, Route, RouteService};
use silent::prelude::{info, logger, HandlerAppend, Level, Route};
use silent::GrpcRegister;

pub mod hello_world {
tonic::include_proto!("helloworld");
tonic::include_proto!("hello_world");
}

#[derive(Default)]
Expand All @@ -18,7 +19,7 @@ impl Greeter for MyGreeter {
&self,
request: Request<HelloRequest>,
) -> Result<Response<HelloReply>, Status> {
println!("Got a request from {:?}", request.remote_addr());
info!("Got a request from {:?}", request.remote_addr());

let reply = hello_world::HelloReply {
message: format!("Hello {}!", request.into_inner().name),
Expand All @@ -32,11 +33,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let greeter = MyGreeter::default();
logger::fmt().with_max_level(Level::INFO).init();

let route = Route::new("").get(|_req| async { Ok("hello world") });
let root = route.route().with_grpc(GreeterServer::new(greeter).into());
let mut route = Route::new("").get(|_req| async { Ok("hello world") });
GreeterServer::new(greeter).register(&mut route);
silent::prelude::Server::new()
.bind("0.0.0.0:50051".parse().unwrap())
.serve(root)
.serve(route)
.await;
Ok(())
}
2 changes: 1 addition & 1 deletion examples/grpc_streaming/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/client.rs"
[dependencies]
tonic = { version = "0.12.3" }
prost = "0.13"
tokio = { version = "1.41", features = ["macros", "rt-multi-thread"] }
tokio = { version = "1.40", features = ["macros", "rt-multi-thread"] }
silent = { path = "../../silent", features = ["grpc"] }
async-trait = "0.1.83"
tokio-stream = "0.1.16"
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc_streaming/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
tonic_build::configure()
.compile(&["proto/echo.proto"], &["/proto"])
.compile_protos(&["proto/echo.proto"], &["/proto"])
.unwrap();
}
2 changes: 1 addition & 1 deletion examples/grpc_streaming/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

println!("Streaming echo:");
streaming_echo(&mut client, 5).await;
tokio::time::sleep(Duration::from_secs(1)).await; //do not mess server println functions
tokio::time::sleep(Duration::from_secs(1)).await; //do not mess server info functions

// Echo stream that sends 17 requests then graceful end that connection
println!("\r\nBidirectional stream echo:");
Expand Down
20 changes: 10 additions & 10 deletions examples/grpc_streaming/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt};
use tonic::{Request, Response, Status, Streaming};

use pb::{EchoRequest, EchoResponse};
use silent::prelude::{logger, HandlerAppend, Level, Route, RouteService, Server};
use silent::prelude::{info, logger, HandlerAppend, Level, Route, RouteService, Server};
use silent::GrpcRegister;

mod client;

Expand Down Expand Up @@ -54,8 +55,8 @@ impl pb::echo_server::Echo for EchoServer {
&self,
req: Request<EchoRequest>,
) -> EchoResult<Self::ServerStreamingEchoStream> {
println!("EchoServer::server_streaming_echo");
println!("\tclient connected from: {:?}", req.remote_addr());
info!("EchoServer::server_streaming_echo");
info!("\tclient connected from: {:?}", req.remote_addr());

// creating infinite stream with requested message
let repeat = std::iter::repeat(EchoResponse {
Expand All @@ -78,7 +79,7 @@ impl pb::echo_server::Echo for EchoServer {
}
}
}
println!("\tclient disconnected");
info!("\tclient disconnected");
});

let output_stream = ReceiverStream::new(rx);
Expand All @@ -100,7 +101,7 @@ impl pb::echo_server::Echo for EchoServer {
&self,
req: Request<Streaming<EchoRequest>>,
) -> EchoResult<Self::BidirectionalStreamingEchoStream> {
println!("EchoServer::bidirectional_streaming_echo");
info!("EchoServer::bidirectional_streaming_echo");

let mut in_stream = req.into_inner();
let (tx, rx) = mpsc::channel(128);
Expand All @@ -121,7 +122,7 @@ impl pb::echo_server::Echo for EchoServer {
if io_err.kind() == ErrorKind::BrokenPipe {
// here you can handle special case when client
// disconnected in unexpected way
eprintln!("\tclient disconnected: broken pipe");
info!("\tclient disconnected: broken pipe");
break;
}
}
Expand All @@ -133,7 +134,7 @@ impl pb::echo_server::Echo for EchoServer {
}
}
}
println!("\tstream ended");
info!("\tstream ended");
});

// echo just write the same data that was received
Expand All @@ -150,9 +151,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
logger::fmt().with_max_level(Level::INFO).init();
let server = EchoServer {};
let route = Route::new("").get(|_req| async { Ok("hello world") });
let root = route
.route()
.with_grpc(pb::echo_server::EchoServer::new(server).into());
let mut root = route.route();
root.push(pb::echo_server::EchoServer::new(server).service());
Server::new()
.bind("0.0.0.0:50051".parse().unwrap())
.serve(root)
Expand Down
23 changes: 2 additions & 21 deletions examples/middleware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ struct MiddleWare {

#[async_trait]
impl MiddleWareHandler for MiddleWare {
async fn pre_request(
&self,
_req: &mut Request,
_res: &mut Response,
) -> Result<MiddlewareResult> {
async fn handle(&self, req: Request, next: &Next) -> Result<Response> {
self.count.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
let count = self.count.load(std::sync::atomic::Ordering::SeqCst);
info!("pre_request count: {}", count);
Expand All @@ -34,21 +30,6 @@ impl MiddleWareHandler for MiddleWare {
msg: "bad request:pre_request".to_string(),
});
}
Ok(MiddlewareResult::Continue)
}
async fn after_response(&self, res: &mut Response) -> Result<MiddlewareResult> {
let count = self.count.load(std::sync::atomic::Ordering::SeqCst);
info!("after_response count: {}", count);
if count % 3 == 0 {
error!("set after_response error");
return Err(SilentError::BusinessError {
code: StatusCode::BAD_REQUEST,
msg: "bad request:after_response".to_string(),
});
}
if let ResBody::Once(body) = res.body() {
println!("body: {:?}", body);
}
Ok(MiddlewareResult::Continue)
next.call(req).await
}
}
2 changes: 1 addition & 1 deletion examples/path_params/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
.append(Route::new("<key:**>/**").get(hello_world))
.append(Route::new("<key>").get(hello_world))
.append(Route::new("<key:other>/other").get(hello_world));
println!("{:?}", route);
info!("{:?}", route);
Server::new().run(route);
}

Expand Down
14 changes: 14 additions & 0 deletions examples/plugin_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "examples_plugin_test"
edition.workspace = true
authors.workspace = true
homepage.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
silent = { path = "../../silent" }
crossbeam-epoch = "0.9.18"
dlopen2 = { version = "0.7.0", features = ["derive"] }
6 changes: 6 additions & 0 deletions examples/plugin_test/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## where is lib from?

Compiled from example project plugins

this example lib is compiled by MacOS, if your system is different, you need to compile it by yourself and edit
lib_path.
Binary file added examples/plugin_test/libexamples_plugins.dylib
Binary file not shown.
21 changes: 21 additions & 0 deletions examples/plugin_test/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crossbeam_epoch::Pointable;
use dlopen2::wrapper::{Container, WrapperApi};
use silent::prelude::{logger, Level, Route, Server};
use std::error::Error;

#[derive(WrapperApi)]
struct PluginApi {
// plugin_metadata: unsafe extern "C" fn() -> PluginMetadata,
#[allow(improper_ctypes_definitions)]
get_route: unsafe extern "C" fn() -> Route,
}

fn main() -> Result<(), Box<dyn Error>> {
logger::fmt().with_max_level(Level::INFO).init();
let lib_path = "./libexamples_plugins.dylib";
let container: Container<PluginApi> =
unsafe { Container::load(lib_path) }.expect("无法加载插件");
let route = unsafe { container.get_route() };
Server::new().run(route);
Ok(())
}
2 changes: 2 additions & 0 deletions examples/plugins/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target-dir = "target"
15 changes: 15 additions & 0 deletions examples/plugins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "examples-plugins"
edition.workspace = true
authors.workspace = true
homepage.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
version.workspace = true

[lib]
crate-type = ['cdylib']

[dependencies]
silent = { path = "../../silent" }
Loading
Loading