feat: Rename api related to protobuf (#1224)
This commit is contained in:
@@ -24,22 +24,22 @@
|
|||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
/// Generated protobuf types from the `grpc.health.v1` package.
|
/// Generated protobuf types from the `grpc.health.v1` package.
|
||||||
pub mod proto {
|
pub mod pb {
|
||||||
#![allow(unreachable_pub)]
|
#![allow(unreachable_pub)]
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
include!("generated/grpc.health.v1.rs");
|
include!("generated/grpc.health.v1.rs");
|
||||||
|
|
||||||
pub const GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET: &[u8] =
|
/// Byte encoded FILE_DESCRIPTOR_SET.
|
||||||
include_bytes!("generated/grpc_health_v1.bin");
|
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("generated/grpc_health_v1.bin");
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET;
|
use super::FILE_DESCRIPTOR_SET;
|
||||||
use prost::Message as _;
|
use prost::Message as _;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn file_descriptor_set_is_valid() {
|
fn file_descriptor_set_is_valid() {
|
||||||
prost_types::FileDescriptorSet::decode(GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET).unwrap();
|
prost_types::FileDescriptorSet::decode(FILE_DESCRIPTOR_SET).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,12 +67,12 @@ impl Display for ServingStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ServingStatus> for proto::health_check_response::ServingStatus {
|
impl From<ServingStatus> for pb::health_check_response::ServingStatus {
|
||||||
fn from(s: ServingStatus) -> Self {
|
fn from(s: ServingStatus) -> Self {
|
||||||
match s {
|
match s {
|
||||||
ServingStatus::Unknown => proto::health_check_response::ServingStatus::Unknown,
|
ServingStatus::Unknown => pb::health_check_response::ServingStatus::Unknown,
|
||||||
ServingStatus::Serving => proto::health_check_response::ServingStatus::Serving,
|
ServingStatus::Serving => pb::health_check_response::ServingStatus::Serving,
|
||||||
ServingStatus::NotServing => proto::health_check_response::ServingStatus::NotServing,
|
ServingStatus::NotServing => pb::health_check_response::ServingStatus::NotServing,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! Contains all healthcheck based server utilities.
|
//! Contains all healthcheck based server utilities.
|
||||||
|
|
||||||
use crate::proto::health_server::{Health, HealthServer};
|
use crate::pb::health_server::{Health, HealthServer};
|
||||||
use crate::proto::{HealthCheckRequest, HealthCheckResponse};
|
use crate::pb::{HealthCheckRequest, HealthCheckResponse};
|
||||||
use crate::ServingStatus;
|
use crate::ServingStatus;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
@@ -132,7 +132,7 @@ impl Health for HealthService {
|
|||||||
match status {
|
match status {
|
||||||
None => Err(Status::not_found("service not registered")),
|
None => Err(Status::not_found("service not registered")),
|
||||||
Some(status) => Ok(Response::new(HealthCheckResponse {
|
Some(status) => Ok(Response::new(HealthCheckResponse {
|
||||||
status: crate::proto::health_check_response::ServingStatus::from(status) as i32,
|
status: crate::pb::health_check_response::ServingStatus::from(status) as i32,
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,11 +152,11 @@ impl Health for HealthService {
|
|||||||
|
|
||||||
let output = async_stream::try_stream! {
|
let output = async_stream::try_stream! {
|
||||||
// yield the current value
|
// yield the current value
|
||||||
let status = crate::proto::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
|
let status = crate::pb::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
|
||||||
yield HealthCheckResponse { status };
|
yield HealthCheckResponse { status };
|
||||||
|
|
||||||
while let Ok(_) = status_rx.changed().await {
|
while let Ok(_) = status_rx.changed().await {
|
||||||
let status = crate::proto::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
|
let status = crate::pb::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
|
||||||
yield HealthCheckResponse { status };
|
yield HealthCheckResponse { status };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -167,8 +167,8 @@ impl Health for HealthService {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::proto::health_server::Health;
|
use crate::pb::health_server::Health;
|
||||||
use crate::proto::HealthCheckRequest;
|
use crate::pb::HealthCheckRequest;
|
||||||
use crate::server::{HealthReporter, HealthService};
|
use crate::server::{HealthReporter, HealthService};
|
||||||
use crate::ServingStatus;
|
use crate::ServingStatus;
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
@@ -176,7 +176,7 @@ mod tests {
|
|||||||
use tonic::{Code, Request, Status};
|
use tonic::{Code, Request, Status};
|
||||||
|
|
||||||
fn assert_serving_status(wire: i32, expected: ServingStatus) {
|
fn assert_serving_status(wire: i32, expected: ServingStatus) {
|
||||||
let expected = crate::proto::health_check_response::ServingStatus::from(expected) as i32;
|
let expected = crate::pb::health_check_response::ServingStatus::from(expected) as i32;
|
||||||
assert_eq!(wire, expected);
|
assert_eq!(wire, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,13 @@
|
|||||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
/// Generated protobuf types from the `grpc.reflection.v1alpha` package.
|
/// Generated protobuf types from the `grpc.reflection.v1alpha` package.
|
||||||
pub mod proto {
|
pub mod pb {
|
||||||
#![allow(unreachable_pub)]
|
#![allow(unreachable_pub)]
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
#![allow(rustdoc::invalid_html_tags)]
|
#![allow(rustdoc::invalid_html_tags)]
|
||||||
include!("generated/grpc.reflection.v1alpha.rs");
|
include!("generated/grpc.reflection.v1alpha.rs");
|
||||||
|
|
||||||
|
/// Byte encoded FILE_DESCRIPTOR_SET.
|
||||||
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("generated/reflection_v1alpha1.bin");
|
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("generated/reflection_v1alpha1.bin");
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::proto::server_reflection_request::MessageRequest;
|
use crate::pb::server_reflection_request::MessageRequest;
|
||||||
use crate::proto::server_reflection_response::MessageResponse;
|
use crate::pb::server_reflection_response::MessageResponse;
|
||||||
pub use crate::proto::server_reflection_server::{ServerReflection, ServerReflectionServer};
|
pub use crate::pb::server_reflection_server::{ServerReflection, ServerReflectionServer};
|
||||||
use crate::proto::{
|
use crate::pb::{
|
||||||
ExtensionNumberResponse, FileDescriptorResponse, ListServiceResponse, ServerReflectionRequest,
|
ExtensionNumberResponse, FileDescriptorResponse, ListServiceResponse, ServerReflectionRequest,
|
||||||
ServerReflectionResponse, ServiceResponse,
|
ServerReflectionResponse, ServiceResponse,
|
||||||
};
|
};
|
||||||
@@ -109,7 +109,7 @@ impl<'b> Builder<'b> {
|
|||||||
/// Build a gRPC Reflection Service to be served via Tonic.
|
/// Build a gRPC Reflection Service to be served via Tonic.
|
||||||
pub fn build(mut self) -> Result<ServerReflectionServer<impl ServerReflection>, Error> {
|
pub fn build(mut self) -> Result<ServerReflectionServer<impl ServerReflection>, Error> {
|
||||||
if self.include_reflection_service {
|
if self.include_reflection_service {
|
||||||
self = self.register_encoded_file_descriptor_set(crate::proto::FILE_DESCRIPTOR_SET);
|
self = self.register_encoded_file_descriptor_set(crate::pb::FILE_DESCRIPTOR_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
for encoded in &self.encoded_file_descriptor_sets {
|
for encoded in &self.encoded_file_descriptor_sets {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use tokio::sync::oneshot;
|
|||||||
use tokio_stream::{wrappers::TcpListenerStream, StreamExt};
|
use tokio_stream::{wrappers::TcpListenerStream, StreamExt};
|
||||||
use tonic::{transport::Server, Request};
|
use tonic::{transport::Server, Request};
|
||||||
use tonic_reflection::{
|
use tonic_reflection::{
|
||||||
proto::{
|
pb::{
|
||||||
server_reflection_client::ServerReflectionClient,
|
server_reflection_client::ServerReflectionClient,
|
||||||
server_reflection_request::MessageRequest, server_reflection_response::MessageResponse,
|
server_reflection_request::MessageRequest, server_reflection_response::MessageResponse,
|
||||||
ServerReflectionRequest, ServiceResponse, FILE_DESCRIPTOR_SET,
|
ServerReflectionRequest, ServiceResponse, FILE_DESCRIPTOR_SET,
|
||||||
|
|||||||
Reference in New Issue
Block a user