mirror of
https://github.com/poem-web/poem.git
synced 2026-01-25 04:18:25 +00:00
Add poem-grpc 3
This commit is contained in:
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -32,6 +32,9 @@ jobs:
|
||||
- name: poem-dbsession-native-tls
|
||||
path: poem-dbsession
|
||||
options: --features __sqlx-native-tls
|
||||
- name: poem-grpc
|
||||
path: poem-grpc
|
||||
options: --all-features
|
||||
services:
|
||||
redis:
|
||||
image: redis:5.0.7
|
||||
|
||||
10
.github/workflows/release.yml
vendored
10
.github/workflows/release.yml
vendored
@@ -4,8 +4,8 @@ on:
|
||||
branches:
|
||||
- release
|
||||
paths:
|
||||
- '**/Cargo.toml'
|
||||
- '.github/workflows/release.yml'
|
||||
- "**/Cargo.toml"
|
||||
- ".github/workflows/release.yml"
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
@@ -33,12 +33,12 @@ jobs:
|
||||
- name: poem-dbsession
|
||||
registryName: poem-dbsession
|
||||
path: poem-dbsession
|
||||
- name: poem-grpc
|
||||
registryName: poem-grpc
|
||||
path: poem-grpc
|
||||
- name: poem-grpc-build
|
||||
registryName: poem-grpc-build
|
||||
path: poem-grpc-build
|
||||
- name: poem-grpc
|
||||
registryName: poem-grpc
|
||||
path: poem-grpc
|
||||
steps:
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
workspace = true
|
||||
avoid_cfg_tarpaulin = true
|
||||
all-features = true
|
||||
exclude = [
|
||||
"poem-dbsession"
|
||||
]
|
||||
exclude = ["poem-dbsession"]
|
||||
exclude-files = [
|
||||
"examples/**/*",
|
||||
"poem-derive/**/*",
|
||||
"poem-openapi-derive/**/*",
|
||||
"poem-dbsession/**/*",
|
||||
"poem-grpc-build/**/*",
|
||||
]
|
||||
|
||||
@@ -8,7 +8,6 @@ poem = { path = "../../../poem" }
|
||||
poem-grpc = { path = "../../../poem-grpc" }
|
||||
prost = "0.11.0"
|
||||
tokio = { version = "1.17.0", features = ["rt-multi-thread", "macros"] }
|
||||
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
|
||||
|
||||
[build-dependencies]
|
||||
poem-grpc-build = { path = "../../../poem-grpc-build" }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use poem::{listener::TcpListener, middleware::Tracing, EndpointExt, Server};
|
||||
use poem::{listener::TcpListener, Server};
|
||||
use poem_grpc::{Request, Response, RouteGrpc, Status};
|
||||
|
||||
poem_grpc::include_proto!("helloworld");
|
||||
@@ -20,16 +20,8 @@ impl Greeter for GreeterService {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
if std::env::var_os("RUST_LOG").is_none() {
|
||||
std::env::set_var("RUST_LOG", "poem=debug");
|
||||
}
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let route = RouteGrpc::new().add_service(GreeterServer::new(GreeterService));
|
||||
Server::new(TcpListener::bind("127.0.0.1:3000"))
|
||||
.run(
|
||||
RouteGrpc::new()
|
||||
.add_service(GreeterServer::new(GreeterService))
|
||||
.with(Tracing),
|
||||
)
|
||||
.run(route)
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
[package]
|
||||
name = "poem-grpc-build"
|
||||
version = "1.3.37"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
authors = ["sunli <scott_s829@163.com>"]
|
||||
description = "Codegen module of poem-grpc."
|
||||
license = "MIT/Apache-2.0"
|
||||
documentation = "https://docs.rs/poem/"
|
||||
homepage = "https://github.com/poem-web/poem"
|
||||
repository = "https://github.com/poem-web/poem"
|
||||
keywords = ["http", "async", "grpc"]
|
||||
categories = ["network-programming", "asynchronous"]
|
||||
|
||||
[dependencies]
|
||||
prettyplease = "0.1.16"
|
||||
@@ -10,3 +18,10 @@ prost-build = "0.10.0"
|
||||
quote = "1.0.17"
|
||||
syn = "1.0.91"
|
||||
proc-macro-crate = "1.1.0"
|
||||
|
||||
[package.metadata.workspaces]
|
||||
independent = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
@@ -81,6 +81,7 @@ pub(crate) fn generate(config: &GrpcConfig, service: &Service, buf: &mut String)
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl #client_ident {
|
||||
#[allow(clippy::let_and_return)]
|
||||
pub fn new(base_url: impl ::std::convert::Into<::std::string::String>) -> Self {
|
||||
Self {
|
||||
cli: {
|
||||
@@ -91,6 +92,7 @@ pub(crate) fn generate(config: &GrpcConfig, service: &Service, buf: &mut String)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::let_and_return)]
|
||||
pub fn from_endpoint<T>(ep: T) -> Self
|
||||
where
|
||||
T: ::poem::IntoEndpoint,
|
||||
|
||||
@@ -120,6 +120,7 @@ pub(crate) fn generate(config: &GrpcConfig, service: &Service, buf: &mut String)
|
||||
type Endpoint = ::poem::endpoint::BoxEndpoint<'static, ::poem::Response>;
|
||||
|
||||
#[allow(clippy::redundant_clone)]
|
||||
#[allow(clippy::let_and_return)]
|
||||
fn into_endpoint(self) -> Self::Endpoint {
|
||||
use ::poem::endpoint::EndpointExt;
|
||||
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
[package]
|
||||
name = "poem-grpc"
|
||||
version = "1.3.37"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
authors = ["sunli <scott_s829@163.com>"]
|
||||
description = "GRPC support for Poem."
|
||||
readme = "README.md"
|
||||
license = "MIT/Apache-2.0"
|
||||
documentation = "https://docs.rs/poem/"
|
||||
homepage = "https://github.com/poem-web/poem"
|
||||
repository = "https://github.com/poem-web/poem"
|
||||
keywords = ["http", "async", "grpc"]
|
||||
categories = ["network-programming", "asynchronous"]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
@@ -26,4 +35,11 @@ serde = { version = "1.0.140", optional = true }
|
||||
serde_json = { version = "1.0.82", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
poem-grpc-build = { path = "../poem-grpc-build", version = "1.3.37" }
|
||||
poem-grpc-build = { path = "../poem-grpc-build", version = "0.2.0" }
|
||||
|
||||
[package.metadata.workspaces]
|
||||
independent = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
84
poem-grpc/README.md
Normal file
84
poem-grpc/README.md
Normal file
@@ -0,0 +1,84 @@
|
||||
<h1 align="center">GRPC support for Poem</h1>
|
||||
|
||||
<div align="center">
|
||||
<!-- Crates version -->
|
||||
<a href="https://crates.io/crates/poem-grpc">
|
||||
<img src="https://img.shields.io/crates/v/poem-grpc.svg?style=flat-square"
|
||||
alt="Crates.io version" />
|
||||
</a>
|
||||
<!-- Downloads -->
|
||||
<a href="https://crates.io/crates/poem-grpc">
|
||||
<img src="https://img.shields.io/crates/d/poem-grpc.svg?style=flat-square"
|
||||
alt="Download" />
|
||||
</a>
|
||||
<!-- docs.rs docs -->
|
||||
<a href="https://docs.rs/poem-grpc">
|
||||
<img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square"
|
||||
alt="docs.rs docs" />
|
||||
</a>
|
||||
<a href="https://github.com/rust-secure-code/safety-dance/">
|
||||
<img src="https://img.shields.io/badge/unsafe-forbidden-success.svg?style=flat-square"
|
||||
alt="Unsafe Rust forbidden" />
|
||||
</a>
|
||||
<a href="https://blog.rust-lang.org/2021/11/01/Rust-1.61.0.html">
|
||||
<img src="https://img.shields.io/badge/rustc-1.61.0+-ab6000.svg"
|
||||
alt="rustc 1.61.0+" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
## Example
|
||||
|
||||
```rust
|
||||
use poem::{listener::TcpListener, Server};
|
||||
use poem_grpc::{Request, Response, RouteGrpc, Status};
|
||||
|
||||
poem_grpc::include_proto!("helloworld");
|
||||
|
||||
struct GreeterService;
|
||||
|
||||
#[poem::async_trait]
|
||||
impl Greeter for GreeterService {
|
||||
async fn say_hello(
|
||||
&self,
|
||||
request: Request<HelloRequest>,
|
||||
) -> Result<Response<HelloReply>, Status> {
|
||||
let reply = HelloReply {
|
||||
message: format!("Hello {}!", request.into_inner().name),
|
||||
};
|
||||
Ok(Response::new(reply))
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
let route = RouteGrpc::new().add_service(GreeterServer::new(GreeterService));
|
||||
Server::new(TcpListener::bind("127.0.0.1:3000"))
|
||||
.run(route)
|
||||
.await
|
||||
}
|
||||
```
|
||||
|
||||
## Safety
|
||||
|
||||
This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% Safe Rust.
|
||||
|
||||
## MSRV
|
||||
|
||||
The minimum supported Rust version for this crate is `1.61.0`.
|
||||
|
||||
## Contributing
|
||||
|
||||
:balloon: Thanks for your help improving the project! We are so happy to have you!
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
* Apache License, Version 2.0,([LICENSE-APACHE](./LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
* MIT license ([LICENSE-MIT](./LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Poem by you, shall be licensed as Apache, without any additional terms or conditions.
|
||||
Reference in New Issue
Block a user